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

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

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

Loading…
Cancel
Save