Created
September 21, 2010 12:38
-
-
Save nestorlafon/589620 to your computer and use it in GitHub Desktop.
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
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