Created
May 15, 2020 14:18
-
-
Save prabhuvikas/38dae6cc44dc782cd5f6451f67cbc329 to your computer and use it in GitHub Desktop.
Promised based create zip file from 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 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