# fork-stream

> Fork a stream in multiple directions according to a function

Latest version **0.0.4** (published 2013-09-13) · BSD license · 0 weekly downloads

## Install

```sh
npm install fork-stream
pnpm add fork-stream
yarn add fork-stream
bun add fork-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2013-09-13 |
| First published | 2013-09-10 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Conrad Pankoff |
| Maintainers | deoxxa |
| Keywords | stream, fork, split, function, conditional |

## Links

- npm: https://www.npmjs.com/package/fork-stream
- Repository: https://github.com/deoxxa/fork-stream
- Issues: https://github.com/deoxxa/fork-stream/issues
- npm.io page: https://npm.io/package/fork-stream

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2013-09-13
- 0.0.3 — 2013-09-12
- 0.0.2 — 2013-09-10
- 0.0.1 — 2013-09-10

## README

fork-stream [![build status](https://travis-ci.org/deoxxa/fork-stream.png)](https://travis-ci.org/deoxxa/fork-stream)
===========

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:

```javascript
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](http://npmjs.org/):

> $ 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.

```javascript
new ForkStream(options);
```

```javascript
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](https://github.com/deoxxa/fork-stream/blob/master/example.js).

```javascript
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
-------

* GitHub ([deoxxa](http://github.com/deoxxa))
* Twitter ([@deoxxa](http://twitter.com/deoxxa))
* Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))

---
_Source: https://npm.io/package/fork-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
