Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Turn an asynchronous function into a through stream
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
.gitignore
LICENCE
README.md
index.js
package.json

README.md

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

Something went wrong with that request. Please try again.