transform-stream

0.2.2 • Public • Published

transform-stream

Turn an transformation function into a through stream

Example

Works both synchronously and asynchronously!

You can also set a boolean to tell the stream to handle each transformation in a serial fashion instead of all of them in parallel.

Backwards compatible with through

var from = require("read-stream").fromArray
    , to = require("write-stream").toArray
 
    , transform = require("transform-stream")
 
from([1,2,3])
    // transform
    .pipe(transform(function (item, finish) {
        setTimeout(function() {
            finish(null, item * 2)
        }, 1000)
    }))
    .pipe(transform(function (item, next, finish) {
        setTimeout(function () {
            next(item * 2)
        }, 500)
 
        setTimeout(function () {
            next(item * 3)
        }, 1000)
 
        setTimeout(function () {
            finish()
        }, 1500)
    }))
    .pipe(transform(function (item) {
        return item * 2
    }))
    .pipe(transform(function (item, finish) {
        console.log("does not")
 
        setTimeout(function () {
            console.log("run in parallel")
            finish(null, item)
        }, 1000)
    }, true))
    .pipe(to(function toList (list) {
        console.log("list", list)
    }))
 

Installation

npm install transform-stream

Contributors

  • Raynos

MIT Licenced

Readme

Keywords

none

Package Sidebar

Install

npm i transform-stream

Weekly Downloads

0

Version

0.2.2

License

none

Last publish

Collaborators

  • raynos