101arrowz / fflate

High performance (de)compression in an 8kB package

Home Page:https://101arrowz.github.io/fflate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: unexpected EOF in browser

lekoala opened this issue · comments

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.

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

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);

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

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?

@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 :-)