0

In node, zlib can be used to decompress partial gzip content (truncated). I tried the same with pako, but looks like it's not working.

This is what I tried:

const s = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8bV23J15O4\xb14\xb1H61417KKLL\xb50L5U\x8a\x05\x00\xf6\xaa\x8e.\x1c\x00\x00\x00";

const truncated = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8bV23J15O4\xb14\xb1H61417KKLL\xb50L5U\x8a\x05\x00\xf6\xaa\x8e.\x1c\x00\x00";  // doesn't work

const array = Uint8Array.from([...s].map(v => v.charCodeAt(0)));

var data        = pako.inflate(array);

var strData2     = String.fromCharCode.apply(null, new Uint16Array(data));

console.log(strData2);

decompressing s works but when I try to decompress truncated i get an empty string.

Update:

tried also with the stream syntax, doesn't work:

const inflate = new pako.Inflate({ level: 3});
inflate.push(array, true);   // tried also false
Moshe Shaham
  • 15,448
  • 22
  • 74
  • 114
  • There is a streaming inflator you can use instead. See https://nodeca.github.io/pako/#Inflate.new – Mark Adler Jul 23 '22 at 06:41
  • @MarkAdler tried it, doesn't work. updated the question what i tried – Moshe Shaham Jul 23 '22 at 06:45
  • Try with `false`, truncating the last eight bytes instead of the last one byte. You can also try feeding a byte at a time. – Mark Adler Jul 23 '22 at 14:49
  • By the way, the `Inflate.new` example on that page makes on sense. They copied it from the `Deflate.new` example. There is no `level` parameter when inflating. And of course the data they are feeding it in the example can't be inflated. – Mark Adler Jul 23 '22 at 21:08
  • Note that you should be able to get the intermediate data with `Inflate#onData`. – Mark Adler Jul 23 '22 at 21:09
  • @MarkAdler sadly, nothing works... http://jsfiddle.net/4qau3e6o/ – Moshe Shaham Jul 24 '22 at 06:15

1 Answers1

1

Use const inflate = new pako.Inflate({chunkSize: 1});. That delivers every byte as it's decompressed to inflate.onData. Provide what you have using inflate.push(stuff, false). Then use inflate.onData to accumulate the bytes as they're generated.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158