fork-stream

WebJar for fork-stream

License

License

BSD
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

fork-stream
Last Version

Last Version

0.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

fork-stream
WebJar for fork-stream
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/deoxxa/fork-stream

Download fork-stream

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/fork-stream/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>fork-stream</artifactId>
    <version>0.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/fork-stream/
implementation 'org.webjars.npm:fork-stream:0.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/fork-stream/
implementation ("org.webjars.npm:fork-stream:0.0.4")
'org.webjars.npm:fork-stream:jar:0.0.4'
<dependency org="org.webjars.npm" name="fork-stream" rev="0.0.4">
  <artifact name="fork-stream" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='fork-stream', version='0.0.4')
)
libraryDependencies += "org.webjars.npm" % "fork-stream" % "0.0.4"
[org.webjars.npm/fork-stream "0.0.4"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

fork-stream build status

Fork a stream in multiple directions according to a function.

Overview

fork-stream basically gives you conditional branching for streams. You supply the logic, fork-stream supplies the streaming.

Super Quickstart

Code:

var ForkStream = require("fork-stream");

var fork = new ForkStream({
  classifier: function classify(e, done) {
    return done(null, e.match(/[aeiou]/));
  },
});

fork.a.on("data", console.log.bind(console, "vowels:"));
fork.b.on("data", console.log.bind(console, "no vowels:"));

fork.write("hello");
fork.write("zxcbzz");
fork.write("ooooooo");

fork.end();

Output:

vowels: hello
no vowels: zxcbzz
vowels: ooooooo

Installation

Available via npm:

$ npm install fork-stream

Or via git:

$ git clone git://github.com/deoxxa/fork-stream.git node_modules/fork-stream

API

constructor

Creates a new fork-stream.

new ForkStream(options);
var fork = new ForkStream({
  highWaterMark: 5,
  classifier: function(e, done) {
    return done(null, !!e);
  },
});
  • options - regular stream options, and a classifier property that fork-stream will use to decide what output stream to send your object down.

Example

Also see example.js.

var ForkStream = require("fork-stream");

var fork = new ForkStream({
  classifier: function classify(e, done) {
    return done(null, e >= 5);
  },
});

fork.a.on("data", console.log.bind(null, "a"));
fork.b.on("data", console.log.bind(null, "b"));

for (var i=0;i<20;++i) {
  fork.write(Math.round(Math.random() * 10));
}

Output:

b 1
a 6
a 9
a 10
a 7
a 5
b 2
b 4
a 8
b 3
a 5
b 4
a 7
a 8
b 1
a 6
b 2
b 0
a 5
b 1

License

3-clause BSD. A copy is included with the source.

Contact

Versions

Version
0.0.4