title: nodejs - downloaded images are corrupt
body: <p>I'm trying to download and image from using http.get in nodejs. The image appears to download but it cannot be opened. The OS complains the file's format appears incorrect. Can someone tell me what I doing wrong here?</p>
  
  <p>Heres an example where I am just trying to grab the Google logo:</p>
  
  <pre><code>    var options = {
      host:'www.google.com',
      port:80,
      path:'/images/srpr/logo3w.png'
  };
  
  
  
      var downloadImage = function (options, fileName) {
          http.get(options, function (res) {
              var imageData;
              res.setEncoding('binary');
              res.on('data', function (chunk) {
                  imageData += chunk;
              });
              res.on('end', function () {
                  fs.writeFile(fileName, imageData, 'binary', function(err){
                      if(err) throw err;
                      console.log('File: ' + fileName + " written!");
                  })
              });
          });
      };
  
  downloadImage(options,'test.png');
  </code></pre>