Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created November 8, 2011 01:30
Show Gist options
  • Save johnboxall/1346761 to your computer and use it in GitHub Desktop.
Save johnboxall/1346761 to your computer and use it in GitHub Desktop.
nodejs: gunzip httpclientresponse w/ zlib
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