Closed webwake closed 5 months ago
I have another code sample. Unzipping works when you send the zip file as one large chunk, but not when you slice it like this (I discovered this by piping the file from https download, so I suppose these are some transmission window sizes).
Code:
const fs = require("node:fs");
const unzipper = require("unzipper");
const data = fs.readFileSync("a.zip");
const extractor = unzipper.Extract({ path: "./test" });
extractor.write(Uint8Array.prototype.slice.call(data, 0, 1378));
extractor.write(Uint8Array.prototype.slice.call(data, 1378, 1378 * 2));
extractor.write(Uint8Array.prototype.slice.call(data, 1378 * 2, 1378 * 3));
extractor.write(Uint8Array.prototype.slice.call(data, 1378 * 3));
The zipfile: a.zip
As a result, the package.json
in output is corrupted like this:
Node: 18.16.0 unzipper: 0.10.11
Downgrading to 18.14.0 fixed issues for me.
Same situation for me after update Node 16 to Node 18.16.0. If I update from Node 16 to Node 18.15.0 there are not errors!
This is the Node changelog for Node 18.16. https://github.com/nodejs/node/releases/tag/v18.16.0
@ZJONSSON can you help me to identify the cause, please?
Hi @mvolfik and @webwake.
Can either of you confirm what I say in my previous comment? In my case using Node 18.15.0 no error occurs. However, the files are corrupted if Node 18.16.0 is used.
May be related to https://github.com/ZJONSSON/node-unzipper/issues/269
Unfortunately, this seems to be reproducible using Node 18.16.0 even with unzipper
version 0.10.14
, which was released after merging https://github.com/ZJONSSON/node-unzipper/pull/274
Is there an update to fix version 18.16 ?
Is there an update to fix version 18.16 ?
It probably does not exist. You may want to migrate to another package. A list of candidates I have researched is written here: https://github.com/go-task/go-npm/issues/7#issuecomment-1568567117
The problem appears to be that unzipper is putting the first block of code in the wrong place.
This is a winmerge comparison of a correctly unzipped file (left) and the results of unzipper on latest node (right). It appears that the very first block from the file has been written to disk later than it should. The resulting file has the same file size but is corrupt.
The problem appears to be that unzipper is putting the first block of code in the wrong place.
Same thing is happening on Node 20.7.0, using unzipper version 0.10.14. In my case it's usually blocks of 2^14 bytes that are being swapped, but it also happens with files much smaller than this.
Would love to see this fixed, as Node 16 has reached end-of-life. There are alternatives, but I really like unzipper's api best, especially the ability to stream archived data without loading it into a buffer first. Very cool!
Very simple application here, all data corrupted by this library
Same issue here.
Also same issue, if I didn't find this page I would have wasted many more hours debugging.
CR v20.10.0
same issue here. all data corrupted by this library. Wasted days on this....
please fix it.
https://www.npmjs.com/package/yauzl#no-streaming-unzip-api - wondering if that's the reason?
So is this library dead? Same issas as almost a year later
The issue has been fixed in the following node.js versions:
But for anyone unable to upgrade, you'll need to switch to a different unzipper library until this gets addressed: https://github.com/ZJONSSON/node-unzipper/issues/261
Thanks @dy-dx for identifying the underlying issue as a bug with fs.createWriteStream
in nodejs. This has now been fixed in node per https://github.com/ZJONSSON/node-unzipper/issues/271#issuecomment-2021223739
As far as extract goes we have moved from unmaintained fstream
to fs-extra
in a newly published version (v0.12.1
)
The extracted files are getting corrupts, this started to happen after upgrading from Node 18 to Node.js 19.8.1 on Windows 10 (haven't tested if broader issue)
Below is a code sample to reproduce the issue. Have incorporated the decompress library to demonstrate an non-corrupt file