through stream that redirects writes to one of two child streams
pipe to many destinations, depending on the results of a function.
basically, represent an
if statement in terms of a stream.
var junction = require'junction-stream'through = require'through'var source = throughchild_1 = throughchild_2 = throughsourcepipejunctionwritepipechild_1pipebloopchild_2pipeblorppipefscreateWriteStream'file'thisresolvedata > 5 ? left : right
create a junction stream.
writefunction takes at least 1 arg, as well
as the list of child streams. it is called against a subinstance of the
junction stream, with a special method,
.resolve(stream) makes the stream write the incoming data to the stream
given as an argument to resolve.
outoforder === false (the default), if the child stream the data is
written to needs to pause, the parent stream will pause as well.
otherwise, the parent stream will ignore all pause requests from the child streams, though they'll still buffer data until they resume.
if you have to asynchronously decide how to resolve, you should call
this.pause() inside the
junctionwritefunctionpipegary = throughmichael = throughbusey = throughreturn thisresolveleft
N children, which will be given as arguments to
works like a normal stream
.pipe operation. no matter which child stream
emits the data, it'll get emitted to the next step in the chain.