nodeca / pako

high speed zlib port to javascript, works in browser & node.js

Home Page:http://nodeca.github.io/pako/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Error: -3" when inflating chunks of data

ceffiong opened this issue · comments

I'm trying to uncompress a .zg file in chunks following the example in the documentation: https://nodeca.github.io/pako/#Inflate.prototype.push but run into error. Could you help me understand and resolve this error?

Browser console output

Response {type: 'basic', url: 'https:/****.rpt.gz', redirected: false, status: 200, ok: true, …}
detail.js:48 ArrayBuffer(29235)
detail.js:49 29235
detail.js:54 ArrayBuffer(8000)
detail.js:54 ArrayBuffer(8000)
detail.js:54 ArrayBuffer(8000)
detail.js:54 ArrayBuffer(5235)
detail.js:57 last chunk
detail.js:64 something is wrong
detail.js:78 Error: -3
at readReport (detail.js:65:10)

Source code

console.log(buf)
console.log(buf.byteLength)
const chunkSize = 8000
var inflate = new pako.Inflate({to: "string"})
for(let i = 0; i < buf.byteLength; i+= chunkSize){
    const chunk = buf.slice(i, i + chunkSize);
    console.log(chunk)
    if(i + chunkSize >= buf.byteLength){
	  inflate.push(chunk, true)
	  console.log("last chunk")
    }else{
	  inflate.push(chunk, false)
    }	
}
if(inflate.err){
    console.log("something is wrong")
    throw new Error(inflate.err)
}
console.log(inflate.result)

Note: I'm doing chunk because I get a "distance too far back error" which I understand means the file is too big to be inflated at once.

Looking forward to your reply,
Charles

I console.log out the inflate object just before the error check and saw the following outputs:

ra {options: {…}, err: -3, msg: 'invalid distance too far back', ended: true, chunks: Array(0), …}
chunks: []
ended: true
err: -3
header: Je {text: 0, time: 0, xflags: 0, os: 0, extra: null, …}
msg: "invalid distance too far back"
options: {chunkSize: 65536, windowBits: -15, to: '', level: 3, raw: true}
strm: qt {input: Uint8Array(8), next_in: 4, avail_in: 4, total_in: 52, output: Uint8Array(65536), …}
[[Prototype]]: Object

Still got "invalid distance too far back" error. Next, I included chunkSize in the pako init e.g. "var inflate = new pako.Inflate({to: "string", chunkSize:8})" but the error persists.

I'm not sure what am doing wrong.

Regards,

I'm having this issue as well. Did you ever figure it out? I need a javascript library for zlib or gzip that can produce the same binary results as the c++ library (for strings/buffers).