Archive without root folder in .zip [node-archiver]

1.5k Views Asked by At

I'm using node-archiver to archive folder "export" with photos inside.

Everything works ok but inside archive I got folder 'offers' and photos are in this folder.

I would like to have like a "flat" .zip, so when I'll unpack my .zip it unpack photos without that 'offers' folder.

My code:

  const folderPath = '/export/.';
  const output = fs.createWriteStream('test/offers.zip');
  const archive = archiver('zip');
  archive.pipe(output);
  archive.directory(folderPath, false);
  archive.finalize();

What I'm getting after unpacking:

image1

What I would like to get:

image2

How can I achieve this?

Regards, Gemmi

1

There are 1 best solutions below

0
On

All you need is set prefix via options property. Like this

archive.directory(folderPath, false, { prefix: 'your destination folder' });

Regards, Lukas