Closed brianignacio5 closed 5 years ago
The most likely cause of corrupted zipfile bugs is the asynchronous operation that writes the zipfile not finishing before you try to read the file. Is there a setup step in your test system that creates the file or copies it from somewhere?
I've often seen people watch for a stream 'end'
event instead of a stream 'finish'
(posix) or 'close'
(windows) event. Could that be the problem here?
In the setup phase I would open an existing file, no creation or copy from somewhere.
I'm using yauzl in a Promise which resolves on the zip file end
event.
Update: Tried the combination of using 'finish'
or 'close'
but the problem still continues. If I'll try to debug it the events are not even reached.
I'm using yauzl in a Promise which resolves on the
end
event, I will try with both finish and close and see how it goes.
I don't follow this. The error you're getting can only come from the yauzl.open()
call, so the 'end'
event or any Promise pattern shouldn't matter. The 'finish'
and 'close'
events I'm referring to are from a fs.createWriteStream()
stream, not from yauzl.
Yes, sorry I was not clear. So 'end'
event I am referring to is the one from zip file. Will update on first post. In the write stream close
event Im doing the same as Cpp tools extension here : https://github.com/Microsoft/vscode-cpptools/blob/master/Extension/src/packageManager.ts#L376
The issue had nothing to do with yauzl, another test was breaking the file. Sorry for the inconvenience.
I have implemented a yauzl.open(path, { lazyEntries: true}, (error, zipfile) => {}); that works fine for normal operation.
The failure happens when I try to do the same inside a mocha test, where the file gives an error when trying to open the zip file as shown here:
After running the test, the zip file is corrupted and if you try to extract it, you get a .zip.cpgz (Im using MacOS Mojave)
Note that is the same file that works when running from the main code. The mocha test use a tdd style. For context, Im using the VScode extension test test runner since I am working on a extension.
If there is anything I can add please let me know.