title: JSON Zip Response in node.js
body: <p>I'm pretty new to node.js and I'm trying to send back a zip file containing JSON results.
  I've been trying to figure it out how to do it, but haven't had the expected results.</p>
  
  <p>I'm using NodeJS, ExpressJS, LocomotiveJS, Mongoose and MongoDB.</p>
  
  <p>Since we're building a mobile oriented application, I'm trying to save as many as bandwith as I can.</p>
  
  <p>The daily initial load for the mobile app could be a big JSON document, so I want to zip it before sending it to the device. If possible I'd like to do it everything in memory in order to avoid disk I/O.</p>
  
  <p>I tried with 3 libraries so far:</p>
  
  <ul>
  <li>adm-zip</li>
  <li>node-zip</li>
  <li>zipstream</li>
  </ul>
  
  <p>The best result I achieved is using node-zip. Here's my code:</p>
  
  <pre><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);
      }
    });
  </code></pre>
  
  <p>The result is a downloaded zip file but the content is unreadable.</p>
  
  <p>I'm pretty sure I'm mixing up things, but to this point I'm not sure how to proceed.</p>
  
  <p>Any advise?</p>
  
  <p>Thanks in advace</p>