stream-map

0.0.1 • Public • Published

STREAM-MAP

An augmentation module for Stream, adds support for map, filter and reduce, The passed functions are applied to the data and their return values writen into the stream again. Internally uses a secondary stream that will be piped to the target one. Please note the following:

  • Reduce must wait for the Stream to end, obviously.
  • To do this, a mapBuffered method is provided.
  • I'm aware that the Stream object will likely change in next node's versions, I'll delete this package as soon as we get support for this functionality.

Some examples

An angry echo server:

var net = require('net');
var Stream = require('..');

net.createServer(function(stream){
    stream.map(function(buff){
        return 'NO, '+buff.toString('utf8').toUpperCase();
    }).pipe(stream);
}).listen('47641');

> echo "are you angry?" | nc localhost 47641
> NO, ARE YOU ANGRY?

An http server that performs byte sums:

var http = require('http');
var Stream = require('..');

http.createServer(function(req, res){
    req.reduce(function(acc, buff){
        acc = parseInt(acc) + buff.length; 
        return acc.toString();
    }, 0).pipe(res);
}).listen('21934');

> curl -XPOST -d @index.js http://localhost:21934 
> 2213

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i stream-map

    Weekly Downloads

    2

    Version

    0.0.1

    License

    none

    Last publish

    Collaborators

    • aynik