Skip to content

Instantly share code, notes, and snippets.

@dayitv89
Forked from dpogorzelski/gunzip.js
Created August 23, 2018 18:04
Show Gist options
  • Save dayitv89/7e013bdf56c8bd4e99e3d90240e0a3d6 to your computer and use it in GitHub Desktop.
Save dayitv89/7e013bdf56c8bd4e99e3d90240e0a3d6 to your computer and use it in GitHub Desktop.
Read http request's body which has a gzip content encoding (node.js);
var https = require('https');
var gunzip = require('zlib').createGunzip();
var options = {
host: 'api.stackexchange.com',
path: '/2.1/info?site=stackoverflow'
};
https.get(options, function(res) {
var body = '';
res.pipe(gunzip);
gunzip.on('data', function (data) {
body += data;
});
gunzip.on('end', function() {
console.log(JSON.parse(body));
});
gunzip.on('error', function(error) {
console.log(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment