Created
June 5, 2013 01:51
-
-
Save Qard/5711086 to your computer and use it in GitHub Desktop.
Gunzip buffers.
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 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