push-to-pull

Convert a push-filter to a pull-filter (for simple streams)

npm install push-to-pull
5 downloads in the last day
46 downloads in the last week
167 downloads in the last month

push-to-pull

Convert a push-filter to a pull-filter (for simple streams)

Usage is simple. Define your filter as an (emit) -> emit transform where emit is (err, item). Then when you need an (stream) -> stream filter, use this module to convert it.

var pushToPull = require('push-to-pull');

// Dumb filter that inputs numbers and outputs that many monkeys
// Encoded as an (emit) -> emit transform filter.
function pushFilter(emit) {
  return function (item) {
    if (item === undefined) return emit();
    for (var i = 1; i <= item; i++) {
      emit("MONKEY " + i);
    }  
  }
}

// Same filter, but as a (stream) -> stream transform filter
var pullFilter = pushToPull(pushFilter);
npm loves you