AsyncUnzipInflate fails on a zip file created by AsyncZipDeflate that contains a zip file
See original GitHub issueIssue Description
How to reproduce
- Create a zip file using a standard tool, or zipSync.
- Use AsyncZipDeflate to add that zip file to a new zip file
- 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.name}`)
stream.ondata = (err, chunk, final) => {
if (err !== null) throw err
fileWriteStream.write(chunk)
if (final) fileWriteStream.end()
}
stream.start()
})
unzipper.register(AsyncUnzipInflate)
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
writeStream.write(data)
if (final) writeStream.end()
})
const file = new AsyncZipDeflate(inputPath)
zip.add(file)
file.push(fs.readFileSync(inputPath), true)
zip.end()
}
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
streamZipAndUnzip('truck.jpg')
// Unzipping a zip file containing another zip file - both created using an off-the-shelf tool - seems to work
unzip('double.zip')
// Using zipSync to zip a zip file and then unzipping seems to work
zipAndUnzip('truck.zip')
// Using AsyncZipDeflate to zip a zip file - fails when unzipping with "Error: invalid distance"
streamZipAndUnzip('truck.zip')
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?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed the SWC minification problems at some point, don’t remember when but SWC minification is not an issue anymore.
Great! Cause I’d forgot about that issue and started using
swcMinify
again anyway. 😃