streamfilter
Filtering streams.
streamfilter
is a function based filter for streams inspired per gulp-filter
but no limited to Gulp nor to objectMode streams.
Installation
First, install streamfilter
in your project:
npm install --save streamfilter
Getting started
There are 3 common usages:
Simple filter
; const filter = { const mustBeFiltered = chunklength > 128; ifmustBeFiltered ; return; ;}; // Print to stdout a filtered stdinprocessstdin ;
Filter and restore
; const filter = { const mustBeFiltered = chunklength > 128; ifmustBeFiltered ; return; ;} restore: true; // Print accepted chunks in stdoutfilter; // Print filtered one to stderrfilterrestore;
Filter and restore as a passthrough stream
Let's reach total hype!
;; // Filter valuesconst filter = { const mustBeFiltered = chunklength > 128; ifmustBeFiltered ; return; ;} restore: true passthrough: true; // Uppercase stringsconst mySuperTransformStream = ; // Pipe stdinprocessstdin // Edit kept chunks // Restore filtered chunks // and output!
Note that in this case, this is your responsibility to end the restore stream by piping in another stream or ending him manually.
API
Stream
StreamFilter(filterCallback, options) ⇒ Filter piped in streams according to the given filterCallback
that takes the
following arguments: chunk
the actual chunk, encoding
the chunk encoding,
filterResultCallbackthe function to call as the result of the filtering process with
truein argument to filter her or
false` otherwise.
Options are passed in as is in the various stream instances spawned by this
module. So, to use the objectMode, simply pass in the options.objectMode
value set to true
.
Kind: global function
Returns: Stream
- The filtering stream
Param | Type | Description |
---|---|---|
filterCallback | function |
Callback applying the filters |
options | Object |
Filtering options |
options.passthrough | boolean |
Set to true , this option change the restore stream nature from a readable stream to a passthrough one, allowing you to reuse the filtered chunks in an existing pipeline. |
options.restore | boolean |
Set to true , this option create a readable stream allowing you to use the filtered chunks elsewhere. The restore stream is exposed in the FilterStream instance as a restore named property. |