Skip to content

Instantly share code, notes, and snippets.

@ferlores
Created July 21, 2012 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ferlores/3157606 to your computer and use it in GitHub Desktop.
Save ferlores/3157606 to your computer and use it in GitHub Desktop.
Example using new Buffer.concat
var http = require('http');
var request = http.request({method: 'get', host: 'images.google.com', port: 80, path: '/intl/en_ALL/images/logos/images_logo_lg.gif'}, function(response) {
var data = [];
response.on('data', function(chunk) {
data.push(chunk);
});
response.on('end', function() {
data = Buffer.concat(data, parseInt(response.headers['content-length']) || undefined);
require('fs').writeFileSync('./test.gif', data, 'binary');
});
});
request.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment