101arrowz / fflate

High performance (de)compression in an 8kB package
https://101arrowz.github.io/fflate
MIT License
2.27k stars 79 forks source link

Error: unexpected EOF in browser #109

Closed lekoala closed 2 years ago

lekoala commented 2 years ago

Hi,

I'm using this library to decode a simple zip file in the browser but I get the following issue

browser.js:211 

       Uncaught (in promise) Error: unexpected EOF
    at Fs (browser.js:258)
    at qp (browser.js:1114)
    at $l (browser.js:1515)

I don't seem to do anything special since i'm doing this: (result is an arraybuffer from a fetch call)

const compressed = new Uint8Array(result);
const decompressed = fflate.decompressSync(compressed);

uncompressing the file in 7zip works fine. The file is created in php with the ZipArchive class. I didn't test yet with other zip files or with another decoding library.

101arrowz commented 2 years ago

Since this is a ZIP file, you need to use the ZIP decompression API. You were trying to decompress with the DEFLATE/GZIP/Zlib API, which is meant for single files, not archives.

const zip = new Uint8Array(result);
const unzipped = fflate.unzipSync(zip);
console.log(unzipped); // This is an object with potentially multiple files
lekoala commented 2 years ago

It doesn't seem to work much better

browser.js:211 
       Uncaught (in promise) Error: invalid zip data
    at Gl (browser.js:2512)

as a comparison, it works with JSZip

    let zip = await JSZip.loadAsync(result);
101arrowz commented 2 years ago

Could you upload or send the ZIP that reproduces this? I haven't found any files that work in JSZip and not fflate.

lekoala commented 2 years ago

@101arrowz sent by email

101arrowz commented 2 years ago

Sorry for the delayed response! I've just tested it and the file works fine on my end, yielding a complete page_0.json. I suspect the issue is that you might be converting your data into a Uint8Array incorrectly. Could you supply the surrounding code, all the way from where you first load the data to where you unzip with fflate?

lekoala commented 2 years ago

@101arrowz so.. not sure what happened (i was probably getting a blob instead of an arraybuffer) but it now seems to work! I believe jszip simply detects the type (arraybuffer or blob) and act accordingly

your library is working great :-)