Skip to content

Commit c132bfc

Browse files
committed
fix: use unzipper as fallback for decompress
1 parent 839e6c7 commit c132bfc

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

bin/helpers/buildArtifacts.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const logger = require('./logger').winstonLogger,
1010

1111
const request = require('request');
1212
const decompress = require('decompress');
13-
13+
const unzipper = require("unzipper");
1414

1515
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
1616
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
@@ -136,13 +136,25 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
136136

137137
const unzipFile = async (filePath, fileName) => {
138138
return new Promise( async (resolve, reject) => {
139-
await decompress(path.join(filePath, fileName), filePath)
140-
.then((files) => {
139+
try {
140+
await decompress(path.join(filePath, fileName), filePath)
141141
resolve();
142-
})
143-
.catch((error) => {
144-
reject(error);
145-
});
142+
} catch (error) {
143+
logger.debug(`Error unzipping with decompress: ${error}, trying with unzipper.`);
144+
try {
145+
fs.createReadStream(path.join(filePath, fileName))
146+
.pipe(unzipper.Extract({ path: filePath }))
147+
.on("close", () => {
148+
resolve();
149+
})
150+
.on("error", (err) => {
151+
reject(err);
152+
});
153+
} catch (unzipperError) {
154+
logger.debug(`Unzip unsuccessful with unzipper`);
155+
}
156+
reject(Constants.debugMessages.BUILD_ARTIFACTS_UNZIP_FAILURE);
157+
}
146158
});
147159
}
148160

bin/helpers/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ const cliMessages = {
271271
},
272272
};
273273

274+
const debugMessages = {
275+
BUILD_ARTIFACTS_UNZIP_FAILURE: "Failed to unzip build artifacts",
276+
};
277+
274278
const messageTypes = {
275279
SUCCESS: "success",
276280
ERROR: "error",
@@ -455,6 +459,7 @@ module.exports = Object.freeze({
455459
syncCLI,
456460
userMessages,
457461
cliMessages,
462+
debugMessages,
458463
validationMessages,
459464
messageTypes,
460465
allowedFileTypes,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"windows-release": "^5.1.0",
3535
"winston": "2.4.4",
3636
"yargs": "14.2.3",
37-
"decompress": "4.2.1"
37+
"decompress": "4.2.1",
38+
"unzipper": "^0.12.3"
3839
},
3940
"repository": {
4041
"type": "git",

0 commit comments

Comments
 (0)