node-archiver
node-archiver copied to clipboard
archiver does not throw error if the target does not exist
If I pass the non-existing path as argument to archiver.directory it does not generate error and does not call error handler, but creates invalid zip file.
I guess this happens because the library relies on global matching and if nothing matches, no path is getting archived (and thus not getting checked)
Example code:
const target = process.argv[2];
const fs = require('fs');
const archiver = require('archiver');
const output = fs.createWriteStream(__dirname + '/example.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
archive.on('error', function(err) {
throw err;
});
archive.pipe(output);
archive.directory(target, false);
archive.finalize();
Run as:
npm start -- path/to/nonexisting-directory