You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says, unzipper will throw Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close but still execute successfully. This happens in Node v18 and higher while using the asyinc iterators.
For example (from the npm page) will throw the error: const zip = fs.createReadStream('path/to/archive.zip').pipe(unzipper.Parse({forceStream: true})); for await (const entry of zip) { const fileName = entry.path; const type = entry.type; // 'Directory' or 'File' const size = entry.vars.uncompressedSize; // There is also compressedSize; if (fileName === "this IS the file I'm looking for") { entry.pipe(fs.createWriteStream('output/path')); } else { entry.autodrain(); } }
I did find a solution for this but couldn't push my branch and make a pull request, it's a one liner so I'll write it here.
In the file lib/parse.js on line 29 before self.emit('close'), I wrote self.emit('end'), which got the code working without the error being thrown.
It would be nice if you could update the repo and the npm package with this change, if this solution doesn't bring any other problems that I'm not aware of.
Please let me know if there's any questions.
The text was updated successfully, but these errors were encountered:
As the title says, unzipper will throw
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
but still execute successfully. This happens in Node v18 and higher while using the asyinc iterators.For example (from the npm page) will throw the error:
const zip = fs.createReadStream('path/to/archive.zip').pipe(unzipper.Parse({forceStream: true})); for await (const entry of zip) { const fileName = entry.path; const type = entry.type; // 'Directory' or 'File' const size = entry.vars.uncompressedSize; // There is also compressedSize; if (fileName === "this IS the file I'm looking for") { entry.pipe(fs.createWriteStream('output/path')); } else { entry.autodrain(); } }
I did find a solution for this but couldn't push my branch and make a pull request, it's a one liner so I'll write it here.
In the file lib/parse.js on line 29 before
self.emit('close')
, I wroteself.emit('end')
, which got the code working without the error being thrown.It would be nice if you could update the repo and the npm package with this change, if this solution doesn't bring any other problems that I'm not aware of.
Please let me know if there's any questions.
The text was updated successfully, but these errors were encountered: