Created
May 15, 2020 14:18
-
-
Save prabhuvikas/280182600e7ccc8d1dc5d795bffc1a4f 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