Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted zip file, created using data event from archiver #770

Open
RakeshPawar opened this issue Jun 27, 2024 · 0 comments
Open

Corrupted zip file, created using data event from archiver #770

RakeshPawar opened this issue Jun 27, 2024 · 0 comments

Comments

@RakeshPawar
Copy link

Hello

I am using archiver to create zip from list of files. and final goal is to stream archived file to azure storage.

Please find below code

{ const archiver = (await import('archiver')).default;
  const archive = archiver('zip');
  
  const p = new Promise((resolve, reject) => {
    archive.on('finish', resolve);
    archive.on('error', err => {
      console.log('error while archiving', err);
      reject(err);
    });

    archive.on('warning', err => {
      if (err.code !== 'ENOENT') {
        reject(err);
      }
    });
    archive.on('data', chunk => {
      appendFile(path.join(cwd, '.build/test2.zip'), chunk) // appending chunks to file , this simulates passing data to passthrough stream by pipe
    });

    archive.pipe(require('fs').createWriteStream('test1.zip')); // steaming to writeStream

    for (const fileOrSubDirPath of filePaths) {
      const relativePath = path.relative(cwd, fileOrSubDirPath);
      archive.file(fileOrSubDirPath, { name: relativePath });
     }

  });
  await archive.finalize();
  await p;
  } 

Using passthrough stream to pass it to azure storage but same result as below,
here for simplicity I created 2 files
test1 -> created using writestream using pipe.
test2 -> created using "chunks" emitted by data event.

I can both files with same size , however I am able unzip test1 , and test2 file is corrupted.

would appreciate any help here :)
thanks in advance !

@RakeshPawar RakeshPawar changed the title Corrupted zip file created using data event from archiver Corrupted zip file, created using data event from archiver Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant