Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-map

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-map

Augments Stream's prototype with map, filter and reduce

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 02 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc