title: Initiate file download with Koa
body: <p>I'm using Koa as a webserver to serve my Polymer application. Upon pressing a button in the frontend <code>localhost:3000/export</code> is called. I would like to deliver a file-download to the client after packing the some files to a zip-archive.</p>
  
  <p><strong>How to do this in Koa.js?</strong></p>
  
  <p><em>Here's an example on how to do it in Express (another option would be the <a href="http://expressjs.com/api.html#res.download" rel="noreferrer">download-helper</a></em></p>
  
  <pre><code>app.get('/export', function(req, res){
  
    var path = require('path');
    var mime = require('mime');
  
    var file = __dirname + '/upload-folder/dramaticpenguin.MOV';
  
    var filename = path.basename(file);
    var mimetype = mime.lookup(file);
  
    res.setHeader('Content-disposition', 'attachment; filename=' + filename);
    res.setHeader('Content-type', mimetype);
  
    var filestream = fs.createReadStream(file);
    filestream.pipe(res);
  });
  </code></pre>
  
  <p>I'm looking for something like this:</p>
  
  <pre><code>router.post('/export', function*(){
    yield download(this, __dirname + '/test.zip')
  })
  </code></pre>