title: Download and save a favicon with node.js?
body: <p>I'm trying to download a favicon from a website using Node.js, but am having some trouble.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>//Imports ...
  
  var theurl = http.createClient(80, 'a1.twimg.com');
  var requestUrl = 'http://a1.twimg.com/a/1284159889/images/favicon.ico';
  var request = theurl.request('GET', requestUrl, {"host": "a1.twimg.com"});
  request.end();
  
  request.addListener('response', function (response)
  {
          var body = '';
          response.addListener('data', function (chunk) {
                  body += chunk;
          });
          response.addListener("end", function() {
              fs.writeFileSync('favicon.ico', body.toString('binary'), 'binary');
          });
  });
  </code></pre>
  
  <p>The resulting icon is just garbage, however, and I suspect it has something to do with the encoding of the favicon when I grab it this way. What's the correct way to do something like this?</p>