1

Im trying to archive my folder that contains multiple files using archivejs library.

As param, Im sending absolute path to the dir that contains my files. I would like to get zipped directory with files in the root of archive. Im creating zip file using createWriteStream. From some reason it does not work properly.

What I want to achieve:

lets say I have folder download where are my files I would like to archive. then Im creating download.zip where I would like to have all my files in the root of archive.

Files weren't written in my zip file means it becomes empty. Where should be the problem ?

function createArchiveZip(destinationDir) {
      const archive = archiver("zip", { zlib: { level: 9 } }); 
      const archiveDir = `${destinationDir}.zip`;
      const zipOutput = fs.createWriteStream(archiveDir);
      console.log("archiveDirarchiveDir",archiveDir);

      zipOutput.on("error", writeStreamError => {
        console.log("writeStreamError", writeStreamError);
      });
      zipOutput.on("end", writeStreamEnd => {
        console.log("writeStream finish", writeStreamEnd);
      });
      archive.on("warning", archiveWarnings => {
        console.log("archiveWarnings", archiveWarnings);
      });
      archive.on("error", archiveErr => {
        console.log("archiveErr", archiveErr);
      });
      archive.pipe(zipOutput);
      archive.directory(destinationDir, false);
      archive.finalize();
      return archiveDir;
    }
Morten
  • 133
  • 4
  • 15
  • no I have let's say folder with name **c6a1bb70-43c0-11e8-8ca7-dd07ab74ae53_download** where are my files which i would like to zip in the folder **c6a1bb70-43c0-11e8-8ca7-dd07ab74ae53_download.zip** with ending _.zip_ but I would like to have these zipped files in root of archive. – Morten Apr 19 '18 at 11:05
  • yes, exactly this package – Morten Apr 19 '18 at 11:15

0 Answers0