Switched from adm-zip to archiver

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent c9218a075f
commit d38834f39e
  1. 25
      BuildServer/lib/tasks/zip.js
  2. 2
      BuildServer/package.json
  3. 12
      BuildServer/routes/release.js

@ -2,30 +2,23 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const Zip = require('adm-zip'); const Archiver = require('archiver');
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { process: () => {
const sourceDirectoryPath = path.normalize(processor.context.exported + "/" + (params.directory || "")); const sourceDirectoryPath = path.normalize(processor.context.exported + "/" + (params.directory || ""));
const targetArchivePath = path.normalize(processor.context.release + "/" + params.archive); const targetArchivePath = path.normalize(processor.context.release + "/" + params.archive);
const zip = new Zip();
processor.onInfo("Compressing '" + params.directory + "' to " + params.archive); processor.onInfo("Compressing '" + params.directory + "' to " + params.archive);
zip.addLocalFolder(sourceDirectoryPath); const output = fs.createWriteStream(targetArchivePath);
zip.toBuffer((buffer) => { const archive = new Archiver("zip");
fs.writeFile(targetArchivePath, buffer, (err) => {
if (err) { output.on("close", () => processor.done());
processor.onError("Unable to write compressed data: " + err);
} else {
processor.onInfo("Compressed");
}
processor.done(); archive.on("error", (err) => processor.onError("Error while compressing: " + err));
}); archive.pipe(output);
}, (error) => { archive.directory(sourceDirectoryPath, false);
processor.onError("Unable to compress: " + error); archive.finalize();
processor.done();
}, () => { }, () => { });
} }
}); });

@ -6,7 +6,7 @@
"start": "forever -c node app.js" "start": "forever -c node app.js"
}, },
"dependencies": { "dependencies": {
"adm-zip": "0.4.7", "archiver": "^1.3.0",
"async": "~2.1.4", "async": "~2.1.4",
"body-parser": "^1.15.2", "body-parser": "^1.15.2",
"cssnano": "^3.9.1", "cssnano": "^3.9.1",

@ -2,7 +2,7 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const Zip = require('adm-zip'); const Archiver = require('archiver');
const getReport = (releasePath, callback) => { const getReport = (releasePath, callback) => {
const reportFile = releasePath + "report.json"; const reportFile = releasePath + "report.json";
@ -51,7 +51,6 @@ module.exports = (req, res, next) => {
rev: req.params.rev rev: req.params.rev
}; };
const zip = new Zip();
const releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/"); const releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/");
getReport(releasePath, (err, report) => { getReport(releasePath, (err, report) => {
@ -59,10 +58,11 @@ module.exports = (req, res, next) => {
return next(err); return next(err);
} }
zip.addLocalFolder(releasePath); const archive = new Archiver("zip");
zip.toBuffer((buffer) => { archive.on("error", next);
res.attachment(options.reponame + '.' + getDatePart(report) + '.' + options.rev + '.zip', '.'); res.attachment(options.reponame + '.' + getDatePart(report) + '.' + options.rev + '.zip', '.');
res.send(buffer); archive.pipe(res);
}, (error) => next(error), () => { }, () => { }); archive.directory(releasePath, false);
archive.finalize();
}); });
}; };

Loading…
Cancel
Save