How to use the archiver.createZip function in archiver

To help you get started, we’ve selected a few archiver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhiokim / haroopad / src / js / vendors / markdown-css / node_modules / grunt-contrib / node_modules / grunt-contrib-compress / node_modules / archiver / examples / pack.js View on Github external
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) {
github enyojs / ares-project / hermes / lib / bdBase.js View on Github external
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);
		}
	});
github gotwarlost / istanbul-middleware / lib / handlers.js View on Github external
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);
github archiverjs / node-archiver / examples / pack-async.js View on Github external
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;
  }

archiver

a streaming interface for archive generation

MIT
Latest version published 9 months ago

Package Health Score

87 / 100
Full package analysis