mirror of
https://github.com/20kaushik02/express-sequelize-backend-template.git
synced 2025-12-06 09:04:06 +00:00
27 lines
597 B
JavaScript
27 lines
597 B
JavaScript
const fs = require("fs");
|
|
const archiver = require('archiver');
|
|
|
|
/**
|
|
* @param {String} sourceDir: /some/folder/to/compress
|
|
* @param {String} outPath: /path/to/created.zip
|
|
* @returns {Promise}
|
|
*/
|
|
function zipDirectory(sourceDir, outPath) {
|
|
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
const stream = fs.createWriteStream(outPath);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
archive
|
|
.directory(sourceDir, false)
|
|
.on('error', err => reject(err))
|
|
.pipe(stream)
|
|
;
|
|
|
|
stream.on('close', () => resolve());
|
|
archive.finalize();
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
zipDirectory,
|
|
} |