I am using the express module on a NodeJS server to create a zip file. The express server responds to many requests, so I know that it is configured correctly, but I'm having problems creating a zip file and sending it back as a download.
I do not want to save the file, and then tell Express to send this file as a download, I just want to send the zip file as data from memory. Here is what I still have.
function buildZipFile(data, filename) { var zip = new require('node-zip')(); zip.file(filename, data, { base64: false }); return zip.generate(); } var data = buildZipFile('hello world', 'hello.txt'); res.set('Content-Type', 'application/zip') res.set('Content-Disposition', 'attachment; filename=file.zip'); res.set('Content-Length', data.length); res.end(data, 'binary'); return;
The file will return, but not one of them will decompress or decompress the ZIP archive, as if it had been corrupted. Any suggestions? Thank you in advance.
James source share