Skip to content

Commit

Permalink
Check preconditions before opening fd
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Apr 3, 2024
1 parent fbb7c88 commit f1603ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/driver/src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ async function getMatchingPkg(
async function downloadFile(url: string | URL, path: string) {
debug("Downloading file from URL:", url);
const response = await fetch(url);
const fileStream = createWriteStream(path);
if (!response.ok || !response.body) {
throw new Error(`Download failed: ${response.statusText}`);
}

const fileStream = createWriteStream(path, { flush: true });

if (response.body) {
for await (const chunk of streamReader(response.body)) {
fileStream.write(chunk);
Expand Down

0 comments on commit f1603ff

Please sign in to comment.