Streamify helps you easily provide a streaming interface for your code.
JavaScript
Latest commit 39b3214 Oct 25, 2017 @fent fent 0.3.0
Permalink
Failed to load latest commit information.
lib remove hashish dep Oct 25, 2017
test update to node >= v4 Oct 25, 2017
.gitattributes use LF line endings in txt files Jun 7, 2014
.gitignore code coverage Aug 28, 2016
.travis.yml update to node >= v4 Oct 25, 2017
LICENSE first commit Jul 16, 2012
README.md update to node >= v4 Oct 25, 2017
package.json 0.3.0 Oct 25, 2017

README.md

node-streamify

Streamify helps you easily provide a streaming interface for your code.

Build Status Dependency Status codecov

Usage

const Streamify = require('streamify');
const request   = require('request');

exports.doSomething = () => {
  var stream = new Streamify();

  request(url1, (err, res, body) => {
    // Do something with `body`.

    // Once the actual stream you want to return is ready,
    // call `stream.resolve()`.
    stream.resolve(request(url2));
  });

  // Your function can return back a stream!!
  return stream;
}

// Because `doSomething()` returns a stream, it can be piped.
exports.doSomething().pipe(anotherStream);

API

streamify([options])

Returns an instance of a stream. options can be

  • superCtor - The object from which it inherits. Defaults to require('stream').Stream. Sometimes you may want to use this if your stream might be checked with the instanceof operator against objects such as http.ServerResponse.
  • readable - Defaults to true.
  • writable - Defaults to true.

Stream#resolve(stream)

Must be called only once when the actual stream you are proxying to becomes available after an asynchronous operation.

Stream#unresolve()

Can be used to unbind a a resolved stream to later call resolve() again.

Stream#addSource(stream)

Add a source readable stream.

Stream#removeSource()

Remove previously added source stream.

Stream#addDest(stream)

Add a destination writable stream.

Stream#removeDest()

Remove a previously added destination stream.

Install

npm install streamify

Tests

Tests are written with mocha

npm test

License

MIT