diff-stream2
Merges two sorted streams into a diffed tuple stream
Example
var through = var DiffStream = // an object map of streams, but could also be an arrayvar stooges = before: through after: through stoogesbeforestoogesbeforestoogesbeforestoogesbefore stoogesafterstoogesafterstoogesafterstoogesafter { return !a ? 1 : !b ? -1 : aid - bid } var diff = tuples // {before: {id: 2, name: "Shemp"}},// {after: {id: 4, name: "Curly"}}
API
DiffStream(streams, [options])
Returns a readable stream.
streams
is a required object or array of readable streams, each of which must already be sorted according to the comparator
. To use an unsorted stream, first pipe it through something like sort-stream2. At this time, only two streams are supported.
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 tofunction(){ return 0 }
. -
evaluator
: an optional function used to evaluate item equality, which defaults to deep-equal.
The returned stream emits values with the same keys as streams
, but with stream data instead of streams for the values. Identical tuples are omitted from the stream, leaving only those that have changed.