Created
November 8, 2011 01:30
-
-
Save johnboxall/1346761 to your computer and use it in GitHub Desktop.
nodejs: gunzip httpclientresponse w/ zlib
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 zlib = require('zlib'); | |
var request = http.get({ | |
host: 'www.bonobos.com', | |
port: 80, | |
path: '/', | |
headers: {'accept-encoding': 'gzip'} | |
}); | |
request.on('response', function(response) { | |
switch (response.headers['content-encoding']) { | |
case 'gzip': | |
console.log('GZIPPED!') | |
var gunzip = zlib.createGunzip(); | |
var content = ''; | |
response.pipe(gunzip); | |
gunzip.on('data', function(chunk) { | |
content += chunk; | |
}); | |
gunzip.on('end', function() { | |
console.log(content); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment