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.

Unhandled error: "invalid distance too far back"

See original GitHub issue

When trying to unzip a large archive (about 45MB that should expand to about 100MB), it fails with this output:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: invalid distance too far back
    at Zlib._binding.onerror (zlib.js:295:17)

Any idea what this means?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

8reactions
coockoocommented, Oct 2, 2017

For anyone who is looking for an answer. I accidentally bumped into this repo (maintainable fork of this one) https://github.com/ZJONSSON/node-unzipper I just replaced my dependency and require line and everything worked like a charm.

1reaction
MaximilianBueglercommented, Dec 29, 2016

The problem isn’t in the unzip library. You were probably using the createReadStream method of the S3 getObject response. This seems to pack an http header in front of the zip file, which causes unzip to rightfully complain about this not being a zip file with the aforementioned error.

Solution is to take the Body of the response, which is a Buffer, convert that to a ReadStream and pipe it into unzip. The BufferStream converter class can be found here: https://gist.github.com/bennadel/b35f3a15cb3b03ddbcf8#file-test-js . (No idea why this isn’t available as a npm package)

So my solution then looks as follows (loose code snippet):


var s3 = new AWS.S3();
var params = {Bucket: s3bucket, Key: zipFileName};
s3.getObject(params,function(err, queryData) {
                if (err){
                    return reject("Loading file "+s3bucket+" : "+zipFileName+" failed. "+err);
                }
                else{
                    var stream=new BufferStream(queryData.Body);
                    var unzipStream=stream.pipe(unzip.Parse());
                    unzipStream.on('error', function(err){ return reject("Unzipping file "+s3bucket+" : "+zipFileName+" failed. "+err); });
                    unzipStream.on('entry', function (entry) {
                                ...

Hope this helps others with this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.util.zip.ZipException: invalid distance too far back while ...
ZipException: invalid distance too far back this exception when i am decompressing my data....it occurs in this line
Read more >
Zlib error: invalid distance too far back · Issue #134429 - GitHub
This is a problem that occurs when connecting the target OS to Linux from the Windows host OS using Remote Development. If you...
Read more >
How to solve the installation error: "Invalid distance-too far ...
The 'invalid distance too far back' error indicates that the MATLAB installer is encountering an error when installing a specific file, which is...
Read more >
Error `invalid distance too far back` when Inflate HTML gZIP ...
It would seem that the file you are trying to "inflate" (decompress using zlib) is not a valid zip file. Since bing.com is...
Read more >
java.util.zip.ZipException: invalid distance too far back
java.util.zip.ZipException: invalid distance too far back ... Most likely some Youtrack files have been corrupted and can no longer be used. A recommended ......
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