I am trying to archive a folder using archiver, the path of the folder that i'd like to archive look like this :
Project
| app.js
| tmp
|
folderToArchive
│file1.txt
│file2.txt
│file3.txt
my server side code where the zip file will be generated look like this :
var archiver = require("archiver");
app.get("/download/:folder", (req, res) => {
var FolderName = req.params.folder;
var zipName = FolderName + ".zip";
var source = path.join(__dirname, "tmp", FolderName);
var out = path.join(__dirname, "tmp", zipName);
const archive = archiver('zip', { zlib: { level: 9 }});
const stream = fs.createWriteStream(out);
return new Promise((resolve, reject) => {
archive
.directory(source, false)
.on('error', err => reject(err))
.pipe(stream)
;
stream.on('close', () => resolve());
archive.finalize();
console.log("zip file created");
});
});
The issue is when i run the app it will create an empty zip file in the right destination.
This is totally new for me and I'd like to understand why the zip file is empty ?
Regards