gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.33k stars 506 forks source link

Excessive Password Prompts During Unzipping with forceZip64 and Password-Protected ZIP Creation #479

Closed shuhei-tagawa closed 5 months ago

shuhei-tagawa commented 5 months ago

Hi, When creating a ZIP file with the forceZip64 option set to true and applying a password, the unzip process prompts for the password for each file entry when extracting. For example, if there are four files within the ZIP, the user is asked to enter the password four times.

The expected behavior is to require the password input only once during the unzip process, regardless of the number of file entries. It seems that my implementation might be incorrect.

// determine forcing ZIP64
const archivePath = "./archiveFolder"
let forceZip64 = false;
let allFiles = fs.readdirSync(archivePath);
for (let file of allFiles) {
  let filePath = path.join(archivePath, file);
  let stat = fs.statSync(filePath);
  const sizeThreshold = 4294967295; // 3.999GB
  if (stat.isFile() && stat.size >= sizeThreshold) {
    forceZip64 = true;
  }
}

const output = fs.createWriteStream("./res");
archive.pipe(output);

let allFiles = fs.readdirSync(archivePath);

// archive zip
for (let file of allFiles) {
    let filePath = path.join(archivePath, file);
    let stat = fs.statSync(filePath);
    if (stat.isFile()) {
        archive.file(filePath, { name: file });
    }
}

archive.finalize();

Thank you in advance.

gildas-lormeau commented 5 months ago

You are using zip.js to unzip the file?

shuhei-tagawa commented 5 months ago

It's my fault. I've forgotten that I'm using another OSS to archive ZIP with password. I'll close this issue. Sorry for bothering.

gildas-lormeau commented 5 months ago

No problem ;)