Skip to content

Instantly share code, notes, and snippets.

@prabhuvikas
Created May 15, 2020 14:18
Show Gist options
  • Save prabhuvikas/38dae6cc44dc782cd5f6451f67cbc329 to your computer and use it in GitHub Desktop.
Save prabhuvikas/38dae6cc44dc782cd5f6451f67cbc329 to your computer and use it in GitHub Desktop.
Promised based create zip file from directory
const archiver = require('archiver');
/**
* @param {String} source
* @param {String} out
* @returns {Promise}
*/
function zipDirectory(source, out) {
const archive = archiver('zip', { zlib: { level: 9 }});
const stream = fs.createWriteStream(out);
return new Promise((resolve, reject) => {
archive
.directory(source, false)
.on('error', err => reject(err))
.pipe(stream)
;
stream.on('close', () => resolve());
archive.finalize();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment