Skip to content

Commit

Permalink
updated version, code formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hgouveia committed Jul 19, 2023
1 parent 2fe344b commit 53da8df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-downloader-helper",
"version": "2.1.7",
"version": "2.1.8",
"description": "A simple http/s file downloader for node.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
33 changes: 17 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class DownloaderHelper extends EventEmitter {
return Promise.resolve(true);
}


if (this.__response) {
this.__response.unpipe();
this.__pipes.forEach(pipe => pipe.stream.unpipe());
Expand Down Expand Up @@ -718,37 +717,39 @@ export class DownloaderHelper extends EventEmitter {
if (!this.__opts.retry || typeof this.__opts.retry !== 'object') {
return Promise.reject(err || new Error('wrong retry options'));
}

const { delay: retryDelay = 0, maxRetries = 999 } = this.__opts.retry;

// reached the maximum retries
if (this.__retryCount >= maxRetries) {
return Promise.reject(err || new Error('reached the maximum retries'));
}

this.__retryCount++;
this.__setState(this.__states.RETRY);
this.emit('retry', this.__retryCount, this.__opts.retry, err);

if (this.__response) {
this.__response.unpipe();
this.__pipes.forEach(pipe => pipe.stream.unpipe());
}

if (this.__fileStream) {
this.__fileStream.removeAllListeners();
}

this.__requestAbort();

return this.__closeFileStream().then(() =>
new Promise((resolve) =>
this.__retryTimeout = setTimeout(() => resolve(this.__downloaded > 0 ?
this.resume() :
this.__start()),
retryDelay)
)
);

return this.__closeFileStream().then(() =>
new Promise((resolve) =>
this.__retryTimeout = setTimeout(
() => resolve(this.__downloaded > 0 ?
this.resume() :
this.__start()),
retryDelay
)
)
);
}

/**
Expand Down

0 comments on commit 53da8df

Please sign in to comment.