node-unzipper
node-unzipper copied to clipboard
Not getting all files extracted
I have a yeoman generator plugin that uses unzipper to extract the contents of a zip file downloaded from github (https://github.com/OfficeDev/office-addin-taskpane/archive/yo-office.zip) as the basis of a new project (see code snippet below). However, after the new version of unzipper was published then the extraction wasn't getting all the files from the zip file, but it wasn't reporting any errors.
readStream.pipe(unzip.Extract({ path: projectFolder }))
.on('error', function (err) {
reject(``Unable to unzip project zip file for "${projectFolder}".\n${err}``);
})
.on('close', async () => {
moveProjectFiles(projectFolder);
resolve();
});
can confirm this is happening to me to on v0.10.14 I have a 'root' zip that contains 36 HTML files, only the first 29 are actually being extracted (no errors).
I resolved by downgrading my version to 0.10.0
Confirming similar behavior after updating from 0.10.5 to 0.10.14
Potentially related: https://github.com/ZJONSSON/node-unzipper/issues/271
Same issue. Downgraded to 0.10.11 to resolve.
Neither 0.10.0 nor 0.10.11 worked.
Same issue. Downgraded to 0.10.11 to resolve.
Any progress on this issue?
Just chiming in to confirm as well. I'm unzipping a WordPress plugin, and I'm consistently not getting the plugin header file, which shares the same name as the .zip being extracted as well as the only and primary subdirectory. So for example, when extracting woocommerce.zip
, expected output is a folder named woocommerce
and a woocommerce.php
file inside. It appears that everything was extracted, but woocommerce.php
is missing.
async function decompressFile(file) {
console.log('Extracting...');
fs.createReadStream(file)
.pipe(unzipper.Extract({ path: outputDirectory })).on('close', function(err) {
if (err) throw err;
console.log('Extraction complete.');
})
return;
}
This is with Unzipper version 0.10.14
@ZJONSSON I would be interested in helping fix whatever regressed between 0.10.11 and 0.10.14 however none of the newer tags have been published to the repo, there's also nothing in GitHub releases.
Are you able to publish the tags so someone can at least try to fix this issue? Alternatively it might be wise to mark the repo as unmaintained as the functionality is broken in such a way that it could cause some really sticky problems.
I also unfortunately have this issue, while downgrading solved it initially I began to have other problems. I have decided to switch to using tar files instead, just leaving as a suggestion for others if they aren't set on zip.
I used https://www.npmjs.com/package/tar
Here is my sample code:
import fs from "fs/promises";
import tar from "tar";
import path from "path";
// Create tar file
async function createTar(FolderToTar: string, outputTarPath: string): Promise<void> {
console.log(`Creating tar file at ${outputTarPath}`);
try {
await tar.create(
{
gzip: false,
file: outputTarPath,
cwd: FolderToTar
},
["."]
);
console.log("Tar creation completed successfully.");
} catch (error) {
console.error(`Error creating tar file: ${error}`);
throw error;
}
}
// Extract tar file
async function extract(directory: string): Promise<void> {
try {
await fs.mkdir(directory, { recursive: true });
const tarFilePath = path.join(__dirname, "bp.tar.gz");
await tar.extract({
file: tarFilePath,
cwd: directory
});
console.log("Extraction completed successfully.");
} catch (error) {
console.error(`Error extracting data: ${error}`);
throw error;
}
}
This is till happening in 0.11.4, is there any alternative package to use?
This is till happening in 0.11.4, is there any alternative package to use?
@HanzCEO I ended up using extract-zip
and haven't had any issues with it. https://www.npmjs.com/package/extract-zip
The extract method in latest release v0.12.1 now use fs-extra
instead of fstream
.
Please also note that certain node versions had a bug related to createWriteStream
, fixed in the following versions:
v18.20.0
v20.12.0
v21.7.1
(see here for more detail)
Please reopen or submit new issue if extract continues to cause problems