Currently I have a directory inside which I have the following files and folder:
---- anExcelFile.xlsx
---- imagesFolder
---------image1.jpg
---------image2.jpg
---------image3.jpg
I want to zip the excel file and all the images keeping the unzipping structure the same as in the folder. Therefore, I want to add the excel file, and the entire images folder to the zip file. Currently my code only zips the excel file and the images folder, but does not add the images inside the folder, to the zip.
My code is
let archiveFile = await helper.zipFile(
"excelAndImages.zip" , process.env.UNZIPPED_EXCEL_FILE_DESTINATION
);
And inside the helper file I have the zipFile function:
zipFile: async (fileName, path) => {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(fileName);
const archive = archiver("zip", {
zlib: { level: 9 },
});
archive.on("error", function (err) {
throw err;
});
archive.pipe(output);
archive.directory(path, false); // Finalize the archive
archive.finalize();
output.on("close", function () {
resolve("done");
});
});
}