daraosn / node-zip

217 stars 38 forks source link

PDF file corrupted when zipped and downloaded #29

Open josephchan91 opened 6 years ago

josephchan91 commented 6 years ago

I'm using PDFKit to generate a PDF file. I want to zip it into a folder together with an excel file. When I download the zip file, I'm getting a 0kb pdf file. The excel file works fine though.

const zip = new require("node-zip")();
zip.file(pdfFilePath, fs.readFileSync(`tmp/${pdfFilePath}`));
const zipData = zip.generate({ base64: false, compression: "DEFLATE" });
const zipFilePath = `tmp/myzipfile.zip`;
fs.writeFileSync(zipFilePath, zipData, "binary");

Any suggestions?