Created
May 27, 2016 23:06
-
-
Save jdcrensh/dd5c7fa93ac4706d919988edacd19f4a to your computer and use it in GitHub Desktop.
[node.js] Archive (zip) files within directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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