2
votes

We've been experimenting with various node unzip modules (adm-zip, unzip, extract-zip) to unzip some fairly large zip files. In almost all of these modules, we notice that the zipping happens successfully the very first time. With the node server running continuously, if there is a request that leads to unzipping a given .zip file again, we notice that all the above modules extract only some of the files and the rest of the files in the zip are missed. Everytime the node server is killed and restarted, the first unzipping happens correctly and subsequently not. What could the reason be for this? We have tried cleaning the directory to which the extracted files are written once we are done with processing them, so every subsequent unzipping always goes to an empty directory.

1
Show us your code ! - dyaa
@dyaa i do not mind showing you the code. as mentioned, we're just leveraging third party node libs for unzipping. the extraction is done as part of a huge application so i am sure there are many dependencies leading to this error. however, i shall update you with the code. - bespectacled
It sounds like you might be reusing variables that shouldn't be reused. In any case, try creating a Minimal, Complete, and Verifiable example. - robertklep

1 Answers

2
votes

I had a similar problem, and in my case, the root cause was that the process was getting terminated before extraction finished.

The key is to make sure you only perform code that can result in garbage cleaning after you have finished extraction. In my case, I was calling window.location (Electron Framework) under the erroneous assumption that the call to Extract() of the unzip module was synchronous).

Here is successful code for me:

fs.createReadStream(fp).pipe(unzipper.Extract({ "path": dirname })
   .on('finish', function() {
      //Extraction done, you can do any cleanup or navigation here. 
      window.location = 'listing.html';
   })
   .on('error', () => console.log("Error"))
)

Perhaps late for you, but likely useful to someone else like myself in the future.