node-unzip
node-unzip copied to clipboard
Hangs with potentially corrupted/invalid/empty zip files
Create an empty file:
$ touch a.zip
Try and unzip using this module:
var fs = require('fs')
, unzip = require('unzip')
, os = require('os')
, zipFile = fs.createReadStream(__dirname + '/a.zip')
, unzipper = unzip.Extract({ path: os.tmpdir() + '/test', verbose: true })
zipFile.on('error', function (err) {
console.error('Zip file error:', err)
})
unzipper.on('error', function (err) {
console.error('Unzipper error:', err)
})
unzipper.on('close', function () {
console.log('Unzipper closed')
})
zipFile.pipe(unzipper)
Hangs forever. Outputting the following verbose log only:
/t/node-unzip-test ❯❯❯ node test.js ⏎
Archive: /private/tmp/node-unzip-test/a.zip
I dont know too much about zip files in general. Is there any way to detect corruption and emit an error somewhere along the line when things arent as they should be?
This is not an issue in yauzl.
I ended up using https://github.com/bower/decompress-zip to detect for corrupted zip files, then this module to stream unzip the contents.
That's a bit of a brittle solution. Seems like you would want the same library that is doing the unzipping to be the one to detect errors and not crash. Anyway if you've got it working then you've got it working. But I do think yauzl would be a more elegant solution :-)
Yeah I agree. If i work on the code again i'll definitely check it out. The failure test cases fill me with confidence https://github.com/thejoshwolfe/yauzl/tree/master/test/failure
I encountered the same problem when the destination is unwriteable. e.g. try running domharrington's code with a real zip file, then chmod -rwx some of the destination files, and try running it again. It will hang forever. An uncaught error is thrown, but neither the error nor close events fire.
+1 had the same problem, switched over to use yauzl which seems like the better choice long term (this one has had no activity since last year)