Skip to content

Commit

Permalink
fix: Create file only when request is started
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Feb 28, 2024
1 parent d667bcb commit 707793b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/common/utils/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ export const downloadFile = (
}
};

const file = fs.createWriteStream(destination);

file.on('error', (err) => {
fs.unlinkSync(destination);
reject(err);
});

file.on('finish', () => {
file.close();
resolve(destination);
});

// find url
https
.get(url, options, (response) => {
Expand All @@ -57,6 +45,18 @@ export const downloadFile = (
return;
}

const file = fs.createWriteStream(destination);

file.on('error', (err) => {
fs.unlinkSync(destination);
reject(err);
});

file.on('finish', () => {
file.close();
resolve(destination);
});

const totalSize = parseInt(
response.headers['content-length']!,
10
Expand Down

0 comments on commit 707793b

Please sign in to comment.