I am new to node.js and I am trying to send back a zip file containing JSON results. I tried to figure out how to do this, but did not expect results.
I use NodeJS, ExpressJS, LocomotiveJS, Mongoose and MongoDB.
Since we are creating a mobile oriented application, I am trying to save as much as possible on tape.
A daily initial download for a mobile application can be a large JSON document, so I want to pin it before sending it to the device. If possible, I would like to do everything in memory to avoid disk I / O.
I tried with 3 libraries:
- admin lightning
- node-zip
- zipstream
The best result I have achieved is to use node-zip. Here is my code:
return Queue.find({'owners': this.param('id')}).select('name extra_info cycle qtype purge purge_time tasks').exec(function (err, docs) { if (!err) { zip.file('queue.json', docs); var data = zip.generate({base64:false,compression:'DEFLATE'}); res.set('Content-Type', 'application/zip'); return res.send(data); } else { console.log(err); return res.send(err); } });
The result is a downloaded zip file, but the contents are unreadable.
I am sure that I am mixing things, but so far I am not sure how to proceed.
Any tips?
Thanks at advace
AkerbeltZ
source share