max-mapper / extract-zip

Zip extraction written in pure JavaScript. Extracts a zip into a directory.
BSD 2-Clause "Simplified" License
391 stars 127 forks source link

Handle zipfile entry error and forward to onEntryError callback option #49

Closed kiejo closed 4 years ago

kiejo commented 7 years ago

This prevents the node process from crashing in case of a zipfile error. I also created a test case to ensure it works as expected. The zip file used in the test has an entry with an absolute path, which causes the yauzl library to emit an error, which causes the node process to crash if not handled.

danrzeppa commented 7 years ago

Why not just call cb passing the error? What's the advantage of having an optional onEntryError callback? Does anyone really want the current behavior of crashing the node process?

kiejo commented 6 years ago

I'm sorry for the late response.

Why not just call cb passing the error? What's the advantage of having an optional onEntryError callback?

A zip file can contain many files of which only one or a few files cause a zipfile error. In such a case the overall zip extraction succeeds with only a few files missing from the output. I think that calling the onEntryError for every zipfile error during the extraction is a better solution than signaling a complete failure by calling the cb after the first zipfile error. It allows the user of the library to work with the successfully extracted files and to optionally handle any failed files.

Does anyone really want the current behavior of crashing the node process?

I don't think anyone wants this behavior, which is why I set up an error listener regardless of whether an onEntryError callback is supplied. This prevents the node process from crashing for all users.

malept commented 4 years ago

Closing in favor of #67