Created
January 2, 2012 05:41
-
-
Save pathsny/1549496 to your computer and use it in GitHub Desktop.
gzip http data
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'); | |
zlib = require('zlib') | |
var request = http.get({ host: 'www.desilva.biz', | |
path: '/php/zlib.html', | |
port: 80, | |
headers: { 'accept-encoding': 'gzip,deflate' } }); | |
request.on('response', function(resp){ | |
var headers = resp.headers['content-encoding'] | |
console.log(headers) | |
console.log('response') | |
console.log(headers.search('gzip') === -1 && headers.search('deflate') === -1) | |
var sol = ''; | |
res2 = resp.pipe(zlib.createGunzip()); | |
res2.on('data', function(chunk){ | |
console.log(chunk) | |
sol += chunk; | |
}); | |
res2.on('end', function(chunk){ | |
console.log(chunk) | |
sol += chunk; | |
console.log("sol", sol); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment