gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.33k stars 506 forks source link

RangeError [ERR_BUFFER_TOO_LARGE] occurs if the ZIP file contains a file larger than 4GB (ZIP64 format) #478

Closed shuhei-tagawa closed 5 months ago

shuhei-tagawa commented 5 months ago

Hi,

When attempting to read data from a ZIP file using entry.getData(writer), a RangeError [ERR_BUFFER_TOO_LARGE] occurs if the ZIP file contains a file larger than 4GB (ZIP64 format). This leads to the termination of the Node.js process.

Is there any way to fix this issue?

const zipFilePath = "./sample.zip"
const buffer = fs.readFileSync(zipFilePath);
const compressed = new Blob([Buffer.from(buffer)], {
  type: "application/zip",
});
const binaryReader = new BlobReader(compressed);
const reader = new ZipReader(binaryReader);
const entries = await reader.getEntries();

for (const [index, entry] of entries.entries()) {
  const writer = new BlobWriter();
  await entry.getData(writer); // RangeError [ERR_BUFFER_TOO_LARGE]: Cannot create a Buffer larger than 4294967295 bytes
  const fileContent = await writer.getData();
}
gildas-lormeau commented 5 months ago

What version of Node.js are you using?

shuhei-tagawa commented 5 months ago

Hi, It's v18.0.0.

I've tried to make own Writer class and pass it to getData() but It hasn't worked so far.

gildas-lormeau commented 5 months ago

I think Node does not support Blobs larger than 4GB actually. Can you paste your Writer implementation?

gildas-lormeau commented 5 months ago

I'm converting this issue to a discussion because it's related to a limitation of Node.js.