Created
July 21, 2012 23:54
-
-
Save ferlores/3157606 to your computer and use it in GitHub Desktop.
Example using new Buffer.concat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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