title: Stream buffer to client in Express
body: <p>I have request handler to send file from MongoDB (GridFS) to client like below, but it use <code>data</code> variable so content is in memory. I need to make this in streaming mode and send file in chunks to client. I can't regognize how to <code>pipe</code> buffer to response. Look at second code - it doesn't work, but show something what i need.</p>
  
  <p>Maybe it is useful: Data in GridFS is Base64 encoded, but may be changed if streaming can be more efficient.</p>
  
  <p><strong>In-Memory version</strong></p>
  
  <pre><code>router.get('/get/:id', function(req,res){
    getById(req.params.id, function(err, fileId){
      new GridStore(db, fileId, "r").open(function(err, gridStore) {
          res.set('Content-Type', gridStore.contentType);
  
          var stream = gridStore.stream(true);
          var data = '';
          stream.on("data", function(chunk) {
              data += chunk;
          });
          stream.on("end", function() {                   
              res.send(new Buffer(data, 'base64'));                   
          });
      });
    });
  });
  </code></pre>
  
  <p><strong>Streaming mode version</strong></p>
  
  <pre><code>router.get('/get/:id', function(req,res){
    getById(req.params.id, function(err, fileId){
      new GridStore(db, fileId, "r").open(function(err, gridStore) {
          res.set('Content-Type', gridStore.contentType);
  
          var stream = gridStore.stream(true);
          stream.on("data", function(chunk) {
              new Buffer(chunk, 'base64').pipe(res);
          });
          stream.on("end", function() {                   
              res.end();
          });
      });
    });
  });
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I think I'm close to resolve this. I found this works, but does't decode from Base64:</p>
  
  <pre><code>new GridStore(db, fileId, "r").open(function(err, gridStore) {
      res.set('Content-Type', gridStore.contentType);
      gridStore.stream(true).pipe(res);
  });
  </code></pre>