title: Node request write to file corrupt
body: <p>I have a get request in node that successfully receives data from API.</p>
  
  <p>When I pipe that response directly to a file like this, it works, the file created is a valid, readable pdf (as i expect to receive from the API).</p>
  
  <pre><code>var http = require('request');
  var fs = require('fs');
  
  http.get(
  {
    url:'',
    headers:{}
  })
  .pipe(fs.createWriteStream('./report.pdf'));
  </code></pre>
  
  <p>Simple, however the file gets corrupted if I use the event emitters of the request like this</p>
  
  <pre><code>  http.get(
  {
    url:'',
    headers:{}
  })
  .on('error', function (err) {
    console.log(err);
  })
  .on('data', function(data) {
    file += data;
  })
  .on('end', function() {
      var stream = fs.createWriteStream('./report.pdf');
      stream.write(file, function() {
        stream.end();
      });
  });
  </code></pre>
  
  <p>I have tried all manner of writing this file and it always ends in a totally blank pdf - the only time the pdf is valid is via the pipe method.</p>
  
  <p>When i console log the events, the sequence seems to be correct - ie, all chunks received and then the <code>end</code> fires at the end.</p>
  
  <p>It's making things impossible to do anything after the pipe. What is pipe doing differently to the writestream ? </p>