1 fork-stream [![build status](https://travis-ci.org/deoxxa/fork-stream.png)](https://travis-ci.org/deoxxa/fork-stream)
4 Fork a stream in multiple directions according to a function.
9 fork-stream basically gives you conditional branching for streams. You supply
10 the logic, fork-stream supplies the streaming.
18 var ForkStream = require("fork-stream");
20 var fork = new ForkStream({
21 classifier: function classify(e, done) {
22 return done(null, e.match(/[aeiou]/));
26 fork.a.on("data", console.log.bind(console, "vowels:"));
27 fork.b.on("data", console.log.bind(console, "no vowels:"));
31 fork.write("ooooooo");
47 Available via [npm](http://npmjs.org/):
49 > $ npm install fork-stream
53 > $ git clone git://github.com/deoxxa/fork-stream.git node_modules/fork-stream
60 Creates a new fork-stream.
63 new ForkStream(options);
67 var fork = new ForkStream({
69 classifier: function(e, done) {
70 return done(null, !!e);
75 * _options_ - regular stream options, and a `classifier` property that
76 fork-stream will use to decide what output stream to send your object down.
81 Also see [example.js](https://github.com/deoxxa/fork-stream/blob/master/example.js).
84 var ForkStream = require("fork-stream");
86 var fork = new ForkStream({
87 classifier: function classify(e, done) {
88 return done(null, e >= 5);
92 fork.a.on("data", console.log.bind(null, "a"));
93 fork.b.on("data", console.log.bind(null, "b"));
95 for (var i=0;i<20;++i) {
96 fork.write(Math.round(Math.random() * 10));
128 3-clause BSD. A copy is included with the source.
133 * GitHub ([deoxxa](http://github.com/deoxxa))
134 * Twitter ([@deoxxa](http://twitter.com/deoxxa))
135 * Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))