Skip to content

Instantly share code, notes, and snippets.

@jdcrensh
Created May 27, 2016 23:06
Show Gist options
  • Save jdcrensh/dd5c7fa93ac4706d919988edacd19f4a to your computer and use it in GitHub Desktop.
Save jdcrensh/dd5c7fa93ac4706d919988edacd19f4a to your computer and use it in GitHub Desktop.
[node.js] Archive (zip) files within directory
const streamBuffers = require('stream-buffers');
const archiver = require('archiver');
const zipDir = (dir) => {
const output = new streamBuffers.WritableStreamBuffer({
initialSize: (100 * 1024), // start at 100 kilobytes.
incrementAmount: (10 * 1024), // grow by 10 kilobytes each time buffer overflows.);
});
const archive = archiver('zip');
archive.on('end', () => {
done(null, output);
});
archive.on('error', done);
archive.pipe(output);
archive.directory(dir, '/');
archive.finalize();
};
zipDir(path.join(__dirname, 'path', 'to', 'directory'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment