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

'end' event not firing.

Open johnwebbcole opened this issue 12 years ago • 14 comments

My unzip routine has stopped working this week because the 'end' event isn't firing.

A code sample that doesn't work is:

function unzip_archive(archive, callback) { console.log("unzip_archive", archive); fs.createReadStream(archive).pipe(unzip.Parse()).on('entry', function(entry) { console.log("unzip", entry.path); entry.pipe(fs.createWriteStream(path.join('temp', entry.path))); }).on('end', function(err) { console.log("unzip"); callback(err); }).on('error', function(err) { console.log("unzip error", err); }).on('finish', function(err) { console.log("unzip finish", err); });

}

I'm running node v0.8.19 and my npm list: ┬ [email protected] ├─┬ [email protected] │ └─┬ [email protected] │ └── [email protected] ├── [email protected] ├─┬ [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ └── [email protected] ├── [email protected] ├─┬ [email protected] │ └── [email protected] ├── [email protected] └── [email protected]

I tried node v0.10 but several libraries are still updating (including unzip) so I've switched back to v0.8, but I'm still not seeing the end event.

johnwebbcole avatar Mar 19 '13 18:03 johnwebbcole

Thanks for reporting the issue. When unzip.Parse has completed receiving data, the end event should fire - I'll have to look into why it isn't.

Are you seeing a close event?

EvanOxfeld avatar Mar 19 '13 18:03 EvanOxfeld

In a zip file containing 11 files, I get one 'finish' event, and a close event at the end.

johnwebbcole avatar Mar 20 '13 13:03 johnwebbcole

I'm also seeing some problems in node 0.8.x. It appears the close event isn't firing.

    var unzipStream = unzip.Extract({ path: path })
    unzipStream.on('error', function () { console.log('Error') })
    unzipStream.on('close', function () { console.log('Close') })
    unzipStream.on('end', function () { console.log('End') })

    var readStream = fs.createReadStream(downloadedFile)
    readStream.pipe(unzipStream)

dpup avatar Mar 20 '13 17:03 dpup

I'm having this same problem on Node 0.8.x. I have just tried (not immediately successfully) to use readable-stream/fs instead of fs to create my read stream thinking that perhaps something had changed in the addition of Node 0.10 compatibility.

dangoor avatar Apr 10 '13 15:04 dangoor

By the way, my use of node-unzip is open source in case that helps track down the problem.

I had pegged node-unzip at 0.1.4 to avoid this problem, but I am having some other trouble now and wanted to get up to the latest version.

dangoor avatar Apr 10 '13 15:04 dangoor

I'll note that my code appears to work if I just listen for a close event rather than an end event. I don't think that's right, but it works.

dangoor avatar May 16 '13 14:05 dangoor

fwiw, we switched to cthackers/adm-zip which has a similar API and works.

dpup avatar May 16 '13 14:05 dpup

@dpup doesn't that just create archives (and this project just extracts archives)? It seems like the two projects serve different purposes.

All of the other unzip libraries I've seen use the pure JS deflater that has unknown licensing.

dangoor avatar May 16 '13 14:05 dangoor

@dangoor Not thinking this morning, copied the wrong package. Updated my comment to avoid confusion.

dpup avatar May 16 '13 14:05 dpup

@dpup Ahh, yes. I had considered a switch to adm-zip, but it contains that same deflater with unknown license. That file is even tagged with "GPL 2.0", though that's not really correct either (if you go to the site with the original file, you'll see that there's no license even mentioned). I totally believe that the intention for that deflater code is that it should be freely usable, but I can't play it loosey goosey with the licensing.

dangoor avatar May 16 '13 15:05 dangoor

I'm not seeing the end or close events on node 0.8.14 with unzip 0.1.8.

justincy avatar Jul 17 '13 16:07 justincy

Node v0.10.0 on ubuntu 13.04. Not seeing close events, but only for some zip files. If I zip up a few sample files on my own, I see the close event getting fired (and also the done event for individual entries in the entry event handler). But the zip files which I app needs to process don't fire these events, even though they get unzipped properly.

FWIW, these files are being zipped by a c#.net application running on windows server 2008, using the ICSharpCode.SharpZipLib.Zip library's ZipOutputStream, using 9 as the compression level. I could do more testing by playing around with the c# code.

Edit: My workaround is using a bash/php script to process zip files. That way, I am offloading the file processing to another process, leaving the node process to handle more requests. I feel that should have been my first approach, now that I think about it.

munimkazia avatar Sep 11 '13 05:09 munimkazia

See also PR https://github.com/EvanOxfeld/node-unzip/pull/100 (temporarily published as unzipper on npm)

ZJONSSON avatar Jul 05 '16 14:07 ZJONSSON

I see the same issue, neither of end or close event is working while extracting zip file. I am on latest version as of today.

codegagan avatar Feb 15 '18 19:02 codegagan