<commit_before>detour-stream
=============

Use boolean expressions/functions to conditionally attach a stream as a *detour* or an *alternative* destination stream.

This module is inspired by [gulp-if](https://github.com/robrich/gulp-if). The difference is that this module is not created for [gulp](https://github.com/gulpjs/gulp).

![](img/flow.png)

Following the above diagram, if **bool** is *unsatisfied*, then data from **stream A** will pass through to **Stream D**.

Otherwise, data will pipe to **Stream B** whenever **bool** is *satisfied*.

If **branch** is true, then data will **not** be piped back to **Stream D**. This is useful when emulating *if/else* with streams.


API
===
<commit_msg>add example<commit_after>detour-stream
=============

Use boolean expressions/functions to conditionally attach a stream as a *detour* or an *alternative* destination stream.

This module is inspired by [gulp-if](https://github.com/robrich/gulp-if). The difference is that this module is not created for [gulp](https://github.com/gulpjs/gulp).

![](img/flow.png)

Following the above diagram, if **bool** is *unsatisfied*, then data from **stream A** will pass through to **Stream D**.

Otherwise, data will pipe to **Stream B** whenever **bool** is *satisfied*.

If **branch** is true, then data will **not** be piped back to **Stream D**. This is useful when emulating *if/else* with streams.

Example
=======

 `detour-stream` is a function that creates a writable stream: https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options

The writable stream is created via `through2 v0.x.y`: https://github.com/rvagg/through2

```js
var detour = require('detour-stream');

stream = fs
  .createReadStream(filepath)
  .pipe(detour(someBoolean, decodeStream(someOptions))) // just pipe it
  .pipe(writeStream);
```

API
===

{'fraction_non_alphanumeric': 0.14587852494577006, 'fraction_numerical': 0.0016268980477223427, 'mean_word_length': 4.857142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6283991', 'n_tokens_mistral': 563, 'n_tokens_neox': 541, 'n_words': 210}