Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tool to wrap your functions so they works as streams.
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tests
.gitignore
README.md
index.js
package.json

README.md

pipemaster

Simple tool to wrap your functions to work as streams. Functions can be both sync and async.

Installation

npm install pipemaster 

Usage

var FuncWrapper = require('pipemaster').FuncWrapper,
    streamFunc;

function asyncExample(x, callback) {
   callback(null, x * x); // first argument is an optional error.
}

streamFunc = new FuncWrapper(asyncExample);

streamFunc.write(2);  // streamFunc emits '4'
streamFunc.write(6);  // streamFunc emits '36'

Sync functions also supported:

var FuncWrapper = require('pipemaster').FuncWrapper,
    streamFunc;

function syncExample(x) {
   return 2 * x;
}

streamFunc = new FuncWrapper(syncExample, false); // 'false' is a flag for sync function

streamFunc.write(2);  // streamFunc emits '4'
streamFunc.write(6);  // streamFunc emits '12'

Filtering stream

Based on FuncWrapper, it takes sync or async function that returns true or false, and emits data event only when function returns true. Filtering functions also can be both sync and async ones.

var StreamFilter = require('pipemaster').StreamFilter,
    streamFunc;
function filterAsync(item, callback) {
    callback(null, item === 4);
}

streamFunc = new StreamFilter(filterAsync, true);

streamFunc.write(1);
streamFunc.write(4);
streamFunc.write(2);

// streamFunc emits only '4'

If you suggest pull requests, please include vows test suites.

Something went wrong with that request. Please try again.