Need to ZIP an entire directory using Node.js -
i need zip entire directory using node.js. i'm using node-zip , each time process runs generates invalid zip file (as can see this github issue).
is there another, better, node.js option allow me zip directory?
edit: ended using archiver
writezip = function(dir,name) { var zip = new jszip(), code = zip.folder(dir), output = zip.generate(), filename = ['jsd-',name,'.zip'].join(''); fs.writefilesync(basedir + filename, output); console.log('creating ' + filename); };
sample value parameters:
dir = /tmp/jsd-<randomstring>/ name = <randomstring>
update: asking implementation used, here's link downloader:
i ended using archiver lib. works great.
var file_system = require('fs'); var archiver = require('archiver'); var output = file_system.createwritestream('target.zip'); var archive = archiver('zip'); output.on('close', function () { console.log(archive.pointer() + ' total bytes'); console.log('archiver has been finalized , output file descriptor has closed.'); }); archive.on('error', function(err){ throw err; }); archive.pipe(output); archive.bulk([ { expand: true, cwd: 'source', src: ['**'], dest: 'source'} ]); archive.finalize();
Comments
Post a Comment