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

Getting duplicate parent zip upon extracting

Open pawan-saxena opened this issue 4 years ago • 1 comments

Hello all, Hope you guys are well and safe. Need some help.

I have written below for zipping a directory :

	const archiver = require('archiver');
	let createArchive = function(sourceDir, destDir) {
		const archive = archiver('zip');
		const stream = fs.createWriteStream(destDir);
		return new Promise((resolve, reject) => {
	    archive
	      .directory(sourceDir, false)
	      .on('error', err => reject(err))
	      .pipe(stream)
	    ;

	    stream.on('close', () => resolve());
	    archive.finalize();
	  });
	}

Before zipping my directory looked like this :

Screenshot 2021-09-16 at 1 18 34 AM

After zipping it looked like this Screenshot 2021-09-16 at 1 20 11 AM

Now when i unzipped the final result looks like this :

Screenshot 2021-09-16 at 1 21 55 AM

The problem is after extracting i can see the duplicate yayy.zip upon opening which it gives me following error. Screenshot 2021-09-16 at 1 22 45 AM

What i am missing ? Is there a way to achieve it without diverting much from my approach, i want to know the issue.

Thank you.

pawan-saxena avatar Sep 15 '21 19:09 pawan-saxena

The .directory() method is working recursive. If this archiver created .zip file when not finish all progress, it is possible to be duplicate .zip in .zip file.

It is better to set .zip destination on different folder or do not use .directory() that can be included location where .zip will be created.

ve3 avatar Jul 06 '22 15:07 ve3