node-archiver icon indicating copy to clipboard operation
node-archiver copied to clipboard

archiver does not throw error if the target does not exist

Open FreeSlave opened this issue 4 years ago • 0 comments

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

FreeSlave avatar Jan 13 '21 11:01 FreeSlave