2017-03-13 23:07:12 +03:00
|
|
|
var fs = require('fs');
|
2016-08-25 10:22:22 +03:00
|
|
|
|
|
|
|
module.exports = function zipFolder(folderToZip, destination, callback) {
|
2017-03-13 23:07:12 +03:00
|
|
|
var archiver = require('archiver'),
|
|
|
|
output = fs.createWriteStream(destination),
|
2016-08-25 10:22:22 +03:00
|
|
|
archive = archiver.create('zip', {});
|
|
|
|
|
2017-07-31 10:48:00 +03:00
|
|
|
// If folder to zip is a symlink, we want to get the target
|
|
|
|
// of the link and zip that instead of zipping the symlink
|
|
|
|
if (fs.lstatSync(folderToZip).isSymbolicLink()) {
|
|
|
|
folderToZip = fs.realpathSync(folderToZip);
|
|
|
|
}
|
|
|
|
|
2016-08-25 10:22:22 +03:00
|
|
|
output.on('close', function () {
|
|
|
|
callback(null, archive.pointer());
|
|
|
|
});
|
|
|
|
|
|
|
|
archive.on('error', function (err) {
|
|
|
|
callback(err, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
archive.directory(folderToZip, '/');
|
|
|
|
archive.pipe(output);
|
|
|
|
archive.finalize();
|
|
|
|
};
|