Skip to content

Commit

Permalink
fix: use unzipper as fallback for decompress
Browse files Browse the repository at this point in the history
  • Loading branch information
asambstack committed Aug 22, 2024
1 parent 839e6c7 commit c132bfc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
26 changes: 19 additions & 7 deletions bin/helpers/buildArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const logger = require('./logger').winstonLogger,

const request = require('request');
const decompress = require('decompress');

const unzipper = require("unzipper");

let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
Expand Down Expand Up @@ -136,13 +136,25 @@ const downloadAndUnzip = async (filePath, fileName, url) => {

const unzipFile = async (filePath, fileName) => {
return new Promise( async (resolve, reject) => {
await decompress(path.join(filePath, fileName), filePath)
.then((files) => {
try {
await decompress(path.join(filePath, fileName), filePath)
resolve();
})
.catch((error) => {
reject(error);
});
} catch (error) {
logger.debug(`Error unzipping with decompress: ${error}, trying with unzipper.`);
try {
fs.createReadStream(path.join(filePath, fileName))
.pipe(unzipper.Extract({ path: filePath }))
.on("close", () => {
resolve();
})
.on("error", (err) => {
reject(err);
});
} catch (unzipperError) {
logger.debug(`Unzip unsuccessful with unzipper`);
}
reject(Constants.debugMessages.BUILD_ARTIFACTS_UNZIP_FAILURE);
}
});
}

Expand Down
5 changes: 5 additions & 0 deletions bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ const cliMessages = {
},
};

const debugMessages = {
BUILD_ARTIFACTS_UNZIP_FAILURE: "Failed to unzip build artifacts",
};

const messageTypes = {
SUCCESS: "success",
ERROR: "error",
Expand Down Expand Up @@ -455,6 +459,7 @@ module.exports = Object.freeze({
syncCLI,
userMessages,
cliMessages,
debugMessages,
validationMessages,
messageTypes,
allowedFileTypes,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"windows-release": "^5.1.0",
"winston": "2.4.4",
"yargs": "14.2.3",
"decompress": "4.2.1"
"decompress": "4.2.1",
"unzipper": "^0.12.3"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit c132bfc

Please sign in to comment.