Can someone please explain to me how the zlib library works in Nodejs?
I\'m fairly new to Nodejs, and I\'m not yet sure how to use buffers and streams.
My si
broofa's answer is great, and that's exactly how I'd like things to work. For me node insisted on callbacks. This ended up looking like:
var zlib = require('zlib');
var input = new Buffer('lorem ipsum dolor sit amet', 'utf8')
zlib.deflate(input, function(err, buf) {
console.log("in the deflate callback:", buf);
zlib.inflate(buf, function(err, buf) {
console.log("in the inflate callback:", buf);
console.log("to string:", buf.toString("utf8") );
});
});
which gives:
in the deflate callback:
in the inflate callback:
to string: lorem ipsum dolor sit amet