Skip to content

Commit

Permalink
Add zipStream destroy call when response is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Duplenskikh committed Oct 3, 2023
1 parent 70c2754 commit e16671a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Extensions/ArtifactEngine/Providers/webProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class WebProvider implements IArtifactProvider {
var downloadSize: number = 0;
var contentType: string = artifactItem.contentType;
var itemUrl: string = artifactItem.metadata['downloadUrl'];
var zipStream = null;
itemUrl = itemUrl.replace(/([^:]\/)\/+/g, "$1");
this.webClient.get(itemUrl, contentType ? { 'Accept': contentType } : undefined).then((res: HttpClientResponse) => {
res.message.on('data', (chunk) => {
Expand All @@ -59,12 +60,17 @@ export class WebProvider implements IArtifactProvider {
this.artifactItemStore.updateDownloadSize(artifactItem, downloadSize);
});
res.message.on('error', (error) => {
if (zipStream) {
zipStream.destroy(error);
Logger.logMessage(error);
}
reject(error);
});

if (res.message.headers['content-encoding'] === 'gzip') {
try {
resolve(res.message.pipe(zlib.createUnzip()));
zipStream = zlib.createUnzip();
resolve(res.message.pipe(zipStream));
}
catch (err) {
reject(err);
Expand Down

0 comments on commit e16671a

Please sign in to comment.