2.0.0 • Published 10 years ago

tuple-stream2 v2.0.0

Weekly downloads
187
License
MIT
Repository
github
Last release
10 years ago

tuple-stream2

build status

Merges multiple streams into an aligned tuple stream.

Example

var through = require("through2")
var TupleStream = require("tuple-stream2")

// an object map of streams, but could also be an array
var stooges = {
  before: through.obj(),
  after: through.obj()
}

stooges.before.write({id: 1, name: "Moe"})
stooges.before.write({id: 2, name: "Shemp"})
stooges.before.write({id: 3, name: "Larry"})
stooges.before.end()

stooges.after.write({id: 1, name: "Moe"})
stooges.after.write({id: 3, name: "Larry"})
stooges.after.write({id: 4, name: "Curly"})
stooges.after.end()

function comparator(a, b){ return !a ? 1 : !b ? -1 : a.id - b.id }

var tuples = TupleStream(stooges, {comparator: comparator})

tuples.on("data", console.log)

//  {before: {id: 1, name: "Moe"  }, after: {id: 1, name: "Moe"}  },
//  {before: {id: 3, name: "Larry"}, after: {id: 3, name: "Larry"}},
//  {before: {id: 2, name: "Shemp"}                               },
//  {                                after: {id: 4, name: "Curly"}}

API

TupleStream(streams, options)

Returns a readable stream.

streams is a required object or array of readable streams.

options is an optional object that can contain the following key:

  • comparator: an optional function used to sort streams. It follows the specification used for Array.prototype.sort, and defaults to function(){ return 0 }.

The returned stream emits values with the same keys as streams, but with stream data instead of streams for the values.

2.0.0

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago