Skip to content

Instantly share code, notes, and snippets.

@Qard
Created June 5, 2013 01:51
Show Gist options
  • Save Qard/5711086 to your computer and use it in GitHub Desktop.
Save Qard/5711086 to your computer and use it in GitHub Desktop.
Gunzip buffers.
var JSONStream = require('JSONStream')
, zlib = require('zlib');
// With compression
var inputA = JSONStream.stringify()
, outputA = JSONStream.parse([true]);
inputA.pipe(zlib.createGzip()).pipe(zlib.createGunzip()).pipe(outputA);
outputA.on('data', function (data) {
console.log('outputA received', data);
});
// Without compression
var inputB = JSONStream.stringify()
, outputB = JSONStream.parse([true]);
inputB.pipe(outputB);
outputB.on('data', function (data) {
console.log('outputB received', data);
});
// Send to each
var timer = setInterval(function () {
inputA.write('{"foo":"bar"}');
inputB.write('{"foo":"bar"}');
}, 25);
setTimeout(function () {
clearInterval(timer);
inputA.end();
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment