Skip to content

Instantly share code, notes, and snippets.

@nestorlafon
Created September 21, 2010 12:38
Show Gist options
  • Save nestorlafon/589620 to your computer and use it in GitHub Desktop.
Save nestorlafon/589620 to your computer and use it in GitHub Desktop.
request.on('response', function (response) {
//var responseBody = '';
var resBuf = new Buffer(10485760);
var resIdx = 0;
sys.debug('STATUS= ' + response.statusCode);
sys.debug('HEADERS= ' + JSON.stringify(response.headers));
//response.setEncoding('utf8');
response.setEncoding('binary');
response.on('data', function(chunk){
resIdx += resBuf.write(chunk, resIdx);
//responseBody += chunk;
});
response.on('end', function(){
if ( 200 == response.statusCode ) {
resBuf.slice(0, resIdx);
sys.debug(sys.inspect(resBuf.toString('binary',resIdx - 10240, resIdx ) ));
sys.debug(resIdx);
var iconv = new Iconv('ISO-8859-1', 'UTF8');
var latinBuf = iconv.convert(resBuf);
htmlemit.emit('done', latinBuf);
//htmlemit.emit('done', responseBody);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment