Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.
/ node-streamify Public archive

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

License

Notifications You must be signed in to change notification settings

fent/node-streamify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-streamify

* Abandoned *

Use a passthrough stream

import { PassThrough } from 'stream';

export myCoolFunction = () => {
  let stream = new PassThrough();
  asyncFunc((err, otherStream) => {
    otherStream.pipe(stream);
  });
}

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

Dependency Status codecov

Usage

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

exports.doSomething = () => {
  let stream = 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

  • 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •