Skip to content

micnews/orderable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

orderable

A readable stream to which you can in random order push chunks or sub-streams with an index, and they will be emitted by index ascending.

build status

Example

var Orderable = require('orderable');

var o = Orderable();

setTimeout(function(){
  o.set(0, 'foo\n');
}, Math.random() * 1000);

setTimeout(function(){
  o.set(1, createStringStream(['b', 'a', 'r', '\n']));
}, Math.random() * 1000);

setTimeout(function(){
  o.set(2, 'baz\n');
  o.set(3, null);
}, Math.random() * 1000);

o.pipe(process.stdout);

Always outputs:

$ node example.js
foo
bar
baz
$

Installation

$ npm install orderable

API

Orderable()

Create an orderable stream.

Orderable#set(index, chunk)

Push chunk onto the internal buffer at index. Pass chunk=null to mark the end of a stream. You can pass readable streams as well.

You can also do this at the beginning, like:

o.set(3, null);
o.set(0, 'foo');
o.set(1, 'bar');
o.set(2, 'baz');

License

MIT

About

Readable stream to which you can push chunks at an index

Resources

Stars

Watchers

Forks

Packages

No packages published