Skip to content

Commit

Permalink
fix(GotDownloader): destroy the writeStream if possible when the down…
Browse files Browse the repository at this point in the history
…load errors (#145)
  • Loading branch information
malept authored Feb 10, 2020
1 parent 7b524f5 commit 2422ca4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/GotDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export class GotDownloader implements Downloader<any> {
const downloadStream = got.stream(url, options);
downloadStream.pipe(writeStream);

downloadStream.on('error', error => reject(error));
downloadStream.on('error', error => {
if (writeStream.destroy) {
writeStream.destroy(error);
}

reject(error);
});
writeStream.on('error', error => reject(error));
writeStream.on('close', () => resolve());
});
Expand Down
3 changes: 0 additions & 3 deletions test/GotDownloader.network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ describe('GotDownloader', () => {
});

it('should throw an error if the file does not exist', async function() {
if (process.platform === 'win32') {
return;
}
const downloader = new GotDownloader();
await withTempDirectory(async dir => {
const testFile = path.resolve(dir, 'test.txt');
Expand Down

0 comments on commit 2422ca4

Please sign in to comment.