0.0.0 • Published 10 years ago

fold-stream v0.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

fold-stream

Build Status

Allows you to iterate over the chunks of a stream and construct a new value that will be passed to a callback. It is similar to [].reduce. In contrast to stream-reduce it does not return a Through, but a function that takes a callback and returns a Writable stream, where the callback will be called with the result. Kind of like using stream-reduce and piping it into concat-stream.

Install it with npm install fold-stream.

Here is an example of how we can use it to create a simple concat stream for Strings:

var fold = require('fold-stream')

var concat = fold(function (acc, curr) {
  return acc + curr
}, '')

process.stdin.pipe(concat(function (result) {
  console.log(result)
}))