|
5 | 5 | use Illuminate\Console\Command;
|
6 | 6 | use Illuminate\Support\Facades\File;
|
7 | 7 | use Illuminate\Support\Facades\Http;
|
| 8 | +use RuntimeException; |
8 | 9 |
|
9 | 10 | class DownloadCommand extends Command
|
10 | 11 | {
|
@@ -46,22 +47,25 @@ public function handle(): int
|
46 | 47 |
|
47 | 48 | $this->info(sprintf('Downloading the Tailwind CSS binary (%s/%s/%s)...', $os, $cpu, $targetVersion));
|
48 | 49 |
|
49 |
| - $contents = Http::timeout($this->option('timeout')) |
50 |
| - ->get($this->downloadUrl($targetArchitecture, $targetVersion)) |
| 50 | + File::ensureDirectoryExists(dirname((string) $targetPath)); |
| 51 | + |
| 52 | + if (File::exists($targetPath)) { |
| 53 | + File::delete($targetPath); |
| 54 | + } |
| 55 | + |
| 56 | + $handle = fopen($targetPath, 'w'); |
| 57 | + |
| 58 | + Http::timeout($this->option('timeout')) |
| 59 | + ->sink($targetPath) |
51 | 60 | ->throw()
|
52 |
| - ->resource(); |
| 61 | + ->get($this->downloadUrl($targetArchitecture, $targetVersion)); |
53 | 62 |
|
54 |
| - if (! $contents) { |
55 |
| - $this->error('Something went wrong when trying to download the Tailwind CSS binary.'); |
| 63 | + fclose($handle); |
56 | 64 |
|
57 |
| - return self::FAILURE; |
| 65 | + if (File::size($targetPath) === 0) { |
| 66 | + throw new RuntimeException('The downloaded binary file is empty.'); |
58 | 67 | }
|
59 | 68 |
|
60 |
| - File::ensureDirectoryExists(dirname((string) $targetPath)); |
61 |
| - if (File::exists($targetPath)) { |
62 |
| - File::delete($targetPath); |
63 |
| - } |
64 |
| - File::put($targetPath, $contents); |
65 | 69 | File::chmod($targetPath, 0755);
|
66 | 70 |
|
67 | 71 | $this->info('Done!');
|
|
0 commit comments