Skip to content

Commit f6f425c

Browse files
committed
Use the sink method from the HTTP Client
1 parent 22bc796 commit f6f425c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Commands/DownloadCommand.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Support\Facades\File;
77
use Illuminate\Support\Facades\Http;
8+
use RuntimeException;
89

910
class DownloadCommand extends Command
1011
{
@@ -46,22 +47,25 @@ public function handle(): int
4647

4748
$this->info(sprintf('Downloading the Tailwind CSS binary (%s/%s/%s)...', $os, $cpu, $targetVersion));
4849

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)
5160
->throw()
52-
->resource();
61+
->get($this->downloadUrl($targetArchitecture, $targetVersion));
5362

54-
if (! $contents) {
55-
$this->error('Something went wrong when trying to download the Tailwind CSS binary.');
63+
fclose($handle);
5664

57-
return self::FAILURE;
65+
if (File::size($targetPath) === 0) {
66+
throw new RuntimeException('The downloaded binary file is empty.');
5867
}
5968

60-
File::ensureDirectoryExists(dirname((string) $targetPath));
61-
if (File::exists($targetPath)) {
62-
File::delete($targetPath);
63-
}
64-
File::put($targetPath, $contents);
6569
File::chmod($targetPath, 0755);
6670

6771
$this->info('Done!');

0 commit comments

Comments
 (0)