Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fs = require('fs');
var archiver = require('archiver');
var async = require('async');
var out = fs.createWriteStream('out.zip'); // or out.tar
var archive = archiver.createZip(); // or createTar
archive.on('error', function(err) {
throw err;
});
archive.pipe(out);
async.forEach(['file1.js', 'file2.js'], function(file, next) {
archive.addFile(fs.createReadStream(file), { name: file }, next);
}, function(err) {
if (err) {
throw err;
}
archive.finalize(function(err, written) {
if (err) {
BdBase.prototype.zip = function(req, res, next) {
log.info("BdBase#zip()", "Zipping '" + req.appDir.zipRoot + "'");
req.zip = {};
req.zip.path = path.join(req.appDir.root, "app.zip");
req.zip.stream = archiver.createZip({level: 1});
req.zip.stream.pipe(fs.createWriteStream(req.zip.path));
_walk.bind(this)(req.appDir.zipRoot, "" /*prefix*/, function(err) {
if (err) {
setImmediate(next, err);
return;
}
try {
req.zip.stream.finalize(function(written){
log.verbose("BdBase#zip()", "finished:", req.zip.path, "(" + written + " bytes)");
setImmediate(next);
});
} catch(e) {
setImmediate(next, e);
}
});
app.get('/download', function (req, res) {
var stream = archiver.createZip(),
writer = new ZipWriter(stream, process.cwd()),
coverageObject = core.getCoverageObject() || {},
collector = new Collector(),
baseDir = process.cwd(),
reports = [
Report.create('html', { writer: writer, dir: path.join(baseDir, 'lcov-report') }),
Report.create('lcovonly', { writer: writer, dir: baseDir })
];
utils.removeDerivedInfo(coverageObject);
collector.add(coverageObject);
res.statusCode = 200;
res.setHeader('Content-type', 'application/zip');
res.setHeader('Content-Disposition', 'attachment; filename=coverage.zip');
stream.pipe(res);
var fs = require('fs');
var archiver = require('archiver');
var async = require('async');
var out = fs.createWriteStream('out.zip');
var archive = archiver.createZip();
archive.on('error', function(err) {
throw err;
});
archive.pipe(out);
async.forEachSeries(['file1.js', 'file2.js'], function(file, next) {
archive.addFile(fs.createReadStream(file), { name: file }, function(err) {
next(err);
});
}, function(err) {
if (err) {
throw err;
}