Skip to content

jfromaniello/funstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Started this to learn about node streams and becuase I thought it was cool.

FilterStream

The callback receives a chunk and has to return true or falsy. If it returns true, the result stream will emit the data event for this chunk.

process.stdin.resume();
process.stdin.pipe(funs.filter(function (chunk) { return chunk.length > 5; }))
             .pipe(process.stdout);

MapStream

Allows to pipe a conversion of the chunks.

process.stdin.resume();
process.stdin.pipe(funs.map(function (chunk) { return "she said: " + chunk; }))
             .pipe(process.stdout);

ReduceStream

Execute the callback, accumulating in the seed, when the source stream ends emit a data event with the result and end the stream.

var aFileStream = fs.createReadStream("foo.txt");
aFileStream.pipe(funs.reduce( function (prev, chunk) { return prev + chunk.match(/o/g).length; }))
             .pipe(funs.map( function (total) { return " total amount of 'o': " + total; }))
             .pipe(process.stdout);

RangeStream

Creates an stream that emits a data event for every number in the range, then ends

funs.range(1, 100).pipe(process.stdout);

DelayStream

The stream emits the data event after an specific amount of milliswcond for every input.

funs.range(1, 100).pipe(funs.delay(100)).pipe(process.stdout);

SerialStream

Receive N input streams and produce a new one that maps the data event of the inputs in a serial way. After an input emits the end event it start reading and maping the data event of the next input. After the last stream ends the result stream ends.

funs.serial(fs.readDir().map(function (f) { return fs.createReadStream(f); })
    .pipe(tar)
    .pipe(gz);

About

Functional programming operations with node.js streams (nothing here yet)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published