101arrowz / fflate

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

Streaming Gunzip breaks sometimes #74

Closed manucorporat closed 3 years ago

manucorporat commented 3 years ago

How to reproduce https://codepen.io/manucorporat/pen/PopXJgb?editors=1010

Notice the:

  const step = 5141811;

With this specific value, the ungzip breaks with Error: invalid length/literal, but works with other values, higher and lower.

This variables allows to rechunk the file into smaller pieces.

This code is an example to minimally reproduce the issue, in production we got this error with random setups.

The problem Gunzip streaming API sometimes errors.

manucorporat commented 3 years ago

Using native Compression Streams https://chromestatus.com/feature/5855937971617792 in chrome works as expected without issues, so I expect this is an real issue

101arrowz commented 3 years ago

Tested this out and I can see the issue. This is a very annoying edge case, I'll fix it in v0.7.1. Thanks for the bug report and the reproducible example.

EDIT: Just FYI, the quick workaround is to gunzip.push(chunk, chunkLength == remaining) and not push with zero length at the end.

101arrowz commented 3 years ago

Should be fixed as v0.7.1. Changing the pen URL to https://cdn.jsdelivr.net/npm/fflate@0.7.1/umd/index.js fixes the bug. Let me know if it isn't resolved.

manucorporat commented 3 years ago

Impressive! works like a charm