1 var stream = require("stream");
3 var ForkStream = module.exports = function ForkStream(options) {
4 options = options || {};
6 options.objectMode = true;
8 stream.Writable.call(this, options);
10 if (options.classifier) {
11 this._classifier = options.classifier;
14 this.a = new stream.Readable(options);
15 this.b = new stream.Readable(options);
19 var resume = function resume() {
27 this.a._read = resume;
28 this.b._read = resume;
30 this.on("finish", function() {
35 ForkStream.prototype = Object.create(stream.Writable.prototype, {constructor: {value: ForkStream}});
37 ForkStream.prototype._classifier = function(e, done) {
38 return done(null, !!e);
41 ForkStream.prototype._write = function _write(input, encoding, done) {
44 this._classifier.call(null, input, function(err, res) {
49 var out = res ? self.a : self.b;
51 if (out.push(input)) {