question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no error or return for pako inflate?

See original GitHub issue

Hi there,

I’m trying to use pako for clientside decompression but for some reason the code doesn’t return the decompressed Uint8Array when using the inflate method. I also don’t see an error getting caught for some reason?

Any help would be great!

https://pakotest.baylyd.repl.co

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rlidwkacommented, Aug 3, 2021

Reproduction sample:

let zlib = require('zlib');
let pako = require('pako');

let sample = zlib.deflateSync(Buffer.from('foobar'));
let sample2 = Buffer.concat([ sample, Buffer.from([ 1 ]) ]);

console.log('zlib sample 1', zlib.inflateSync(sample));
// outputs <Buffer 66 6f 6f 62 61 72>

console.log('pako sample 1', pako.inflate(sample));
// outputs Uint8Array(6) [ 102, 111, 111, 98, 97, 114 ]

console.log('zlib sample 2', zlib.inflateSync(sample2));
// outputs <Buffer 66 6f 6f 62 61 72>

console.log('pako sample 2', pako.inflate(sample2));
// outputs undefined
0reactions
DevinBaylycommented, Aug 3, 2021

really? one extra byte made all the difference I suppose.

The length of the compressed data was something that I calculated using the first 4 bytes of the chunk header pasted again here image but it’s entirely on me that there’s an off by one error in calculating the length of the compressed data.

So in a sense the extra byte in the binary file comes from me supplying one too many bytes probably by computing the length in bytes of the compressed data wrong with this code

function compute_chunk_size(hdr) {
  return hdr.reduce((acc, cur, i) => {
    // the header is 4 bytes so 0-3 are the i's
    return acc + (cur << (8 * (3 - i)));
  }, 0);
}

supplying the [0,0,15,131] as the hdr parameter above

I guess I shouldn’t expect pako to speak up in cases like this with an error thrown though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failing to inflate a sequence of bytes · Issue #174 · nodeca/pako
The problem is, that pako.js can not do Deflate decompression. ... the content of file.log var bytes = pako.inflate(buf); // throws an error...
Read more >
Pako js returns invalid result after inflate - Stack Overflow
Chrome throws me an error: "Uncaught SyntaxError: Unexpected identifier", because pako gives invalid code. So, perhaps, problem with charset ...
Read more >
pako 2.1.0 API documentation
Sends input data to inflate pipe, generating Inflate#onData calls with new output chunks. Returns true on success. If end of stream detected, ...
Read more >
How to use the pako.inflateRaw function in pako - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately. ... inflateRaw(data)); } catch (e)...
Read more >
fflate - npm
fflate (short for fast flate) is the fastest, smallest, and most versatile pure JavaScript compression and decompression library in existence, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found