node-unzipper icon indicating copy to clipboard operation
node-unzipper copied to clipboard

Not getting all files extracted

Open millerds opened this issue 1 year ago • 12 comments

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();
            });

millerds avatar May 11 '23 21:05 millerds

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

MasterDover avatar May 16 '23 20:05 MasterDover

Confirming similar behavior after updating from 0.10.5 to 0.10.14

ColeMurray avatar Jun 11 '23 21:06 ColeMurray

Potentially related: https://github.com/ZJONSSON/node-unzipper/issues/271

ColeMurray avatar Jun 11 '23 21:06 ColeMurray

Same issue. Downgraded to 0.10.11 to resolve.

jasondalycan avatar Jun 29 '23 21:06 jasondalycan

Neither 0.10.0 nor 0.10.11 worked.

mayankk96 avatar Jul 10 '23 05:07 mayankk96

Same issue. Downgraded to 0.10.11 to resolve.

bpavlov avatar Sep 05 '23 15:09 bpavlov

Any progress on this issue?

millerds avatar Oct 10 '23 21:10 millerds

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

mjones129 avatar Oct 25 '23 07:10 mjones129

@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.

tommoor avatar Nov 12 '23 19:11 tommoor

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;
  }
}

philipgriffin avatar Nov 29 '23 19:11 philipgriffin

This is till happening in 0.11.4, is there any alternative package to use?

HanzCEO avatar Apr 29 '24 05:04 HanzCEO

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

mjones129 avatar Apr 29 '24 14:04 mjones129

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

ZJONSSON avatar Jun 08 '24 20:06 ZJONSSON