and-stream
Node.js Stream to filter multiple-streams of incoming objects, and only return objects that are present in ALL streams.
Installation
Install via npm:
$ npm install and-stream
Examples
Only print out objects that are present in two input object streams
var andStream = require('and-stream');
var and = andStream();
and
.on('data', console.log)
.on('end', process.exit);
aStreamOfObjects()
.pipe(and.stream());
anotherStreamOfObjects()
.pipe(and.stream());
The and-stream
constructor takes an optional argument which is used to
determine the unique key to identify an object by. If not used, it will
default to using JSON.stringify
to uniquely identify each object, so only
if the exact same object is present on all streams will the objected be
emmitted by the and-stream
.
Use the name
property on the object as the object key
var andStream = require('and-stream');
var and = andStream('name');
and
.on('data', console.log)
.on('end', process.exit);
aStreamOfObjects()
.pipe(and.stream());
anotherStreamOfObjects()
.pipe(and.stream());
Use a custom function on the objects to determine the key
var andStream = require('and-stream');
var and = andStream(function (data) {
var strKey = data.name;
var useKey = new Buffer(strKey, 'utf8').toString('base64');
return useKey;
});
and
.on('data', console.log)
.on('end', process.exit);
aStreamOfObjects()
.pipe(and.stream());
anotherStreamOfObjects()
.pipe(and.stream());