0

I am trying to replicate the functionality of the following shell command using archiverJS, in my application.

zip -r archiveName *

this is how I am doing it currently:-

const targetArchiveFile = fs.createWriteStream(`${rootFolder}/${zipFileName}.zip`);
const archive = archiver('zip', {
  zlib: { level: 9 },
});

archive.pipe(targetArchiveFile);
archive.on('error', function (error) {
  throw error;
});

archive.glob('**/!(*.zip)', { cwd: rootFolder }); 
archive.finalize();

Since I am saving the zip file in the same directory that is being archived, it fails unless I ignore the archive file itself using the glob pattern '**/!(*.zip)'. However this also ignores all other zip files in the directory which I do not want. I tried to ignore the specific file like below, but it does not work.

archive.glob('**/*', { cwd: rootFolder, ignore: [`${rootFolder}/${zipFileName}.zip`] }); 

Is there a better way to ignore the specific zip file without ignoring all zip files all together?

4

0 回答 0