Error received when opening a downloaded zip file.
Error Opening a downloaded zip file
NodeJS Server: SPDY and Express using http2
I have created an api route to download a zip file. The zip file downloaded in Chrome/Firefox is corrupt, but when tested the same route in Postman with "Send and Download". I was able to get the file and was able to open the zip file
Code to generate archive file on the server side and pipe it to the response
const archive: archiver.Archiver = archiver('zip');
archive.on('error', error => next(new ServerError(500, error.message)));
archive.on('end', () => {
console.log(`Total bytes: ${archive.pointer()}`);
res.end();
});
archive.pipe(res);
strArr.forEach((str, idx) => archive.append(str, { name: `${idx}.txt` }));
archive.finalize();
There is a difference in the file sizes that are downloaded
In all these 3 requests to backend, the API returned the same number of bytes
Total bytes: 27137312