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.

AsyncUnzipInflate fails on a zip file created by AsyncZipDeflate that contains a zip file

See original GitHub issue

How to reproduce

  1. Create a zip file using a standard tool, or zipSync.
  2. Use AsyncZipDeflate to add that zip file to a new zip file
  3. Try to unzip using AsyncUnzipInflate
const fs = require('fs')
const { zipSync, Zip, Unzip, AsyncZipDeflate, AsyncUnzipInflate } = require('fflate')

function unzip (zipPath) {
  const zipped = fs.readFileSync(zipPath)
  const unzipper = new Unzip(stream => {
    const fileWriteStream = createWriteStream(`out_${}`)
    stream.ondata = (err, chunk, final) => {
      if (err !== null) throw err
      if (final) fileWriteStream.end()
  unzipper.push(zipped, true)

function streamZipAndUnzip (inputPath) {
  const outputPath = `stream_zipped_${inputPath}.zip`
  const writeStream = fs.createWriteStream(outputPath)
  writeStream.once('finish', () => unzip(outputPath))

  const zip = new Zip((err, data, final) => {
    if (err !== null) throw err
    if (final) writeStream.end()

  const file = new AsyncZipDeflate(inputPath)
  file.push(fs.readFileSync(inputPath), true)


function zipAndUnzip (inputPath) {
  const outputPath = `zipped_${inputPath}.zip`
  const zipped = zipSync({
    [inputPath]: fs.readFileSync(inputPath)
  fs.writeFileSync(outputPath, zipped)

// Zipping and unzipping a plain JPG seems to work

// Unzipping a zip file containing another zip file - both created using an off-the-shelf tool - seems to work

// Using zipSync to zip a zip file and then unzipping seems to work

// Using AsyncZipDeflate to zip a zip file - fails when unzipping with "Error: invalid distance"

The problem

Error: invalid distance when unzipping a zip file created using AsyncZipDeflate which contains another zip file.

It seems that when unzipping the outer zip file, it also tries to unzip the inner zip file, which is surprising behaviour? truck.jpg

Issue Analytics

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

github_iconTop GitHub Comments

101arrowzcommented, Mar 23, 2022

Fixed the SWC minification problems at some point, don’t remember when but SWC minification is not an issue anymore.

DustinBrettcommented, Mar 23, 2022

Great! Cause I’d forgot about that issue and started using swcMinify again anyway. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

101arrowz/fflate: High performance (de)compression ... - GitHub
You can create multi-file ZIP archives easily as well. Note that by default, compression is enabled for all files, which is not useful...
Read more >
Cannot Open Zipped File? A Full Guide to Fix It!
This article will explain why you cannot open zip files, shows you how to open corrupted zip files, and lists tools for unzipping...
Read more >
Zip and unzip files - Microsoft Support
To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the...
Read more >
zipfile — Work with ZIP archives — Python 3.11.1 documentation
The ZIP file format is a common archive and compression standard. This module provides tools to create, read, write, append, and list a...
Read more >
Maven project with PI4J library - error in opening zip file
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project kosciol-main: Error creating shaded jar: error in ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found