Reputation: 28402
I'm getting contents of a gzipped web page in chunks and want to decompress each as soon as it gets received, so I'm trying to do (stuff stripped for readability):
var decompress = function(string, callback) {
zlib.gunzip(string, callback);
};
decompress(chunk, function(data) {
console.log(data);
});
However I'm only getting null
s logged to the console. My node version is 0.6.2 and zlib
is the built-in one. How should I decompress it?
Upvotes: 4
Views: 6123
Reputation: 18217
If you want to pipe contents to Gunzip, use zlib#createGunzip()
http.get(options, function(res) {
var gunzip = zlib.createGunzip();
res.pipe(gunzip);
gunzip.on('data', function(data) {
console.log(data);
});
}).on('error', function(e) {
console.error(e)
});
Upvotes: 10