diff-stream2

1.0.4 • Public • Published

diff-stream2

build status

Merges two sorted streams into a diffed tuple stream

Example

var through = require("through2")
var DiffStream = require("diff-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 !? 1 : !? -1 : a.id - b.id }
 
var diff = DiffStream(stooges, {comparator: comparator})
 
tuples.on("data", console.log)
 
//  {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 to function(){ 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.

Readme

Keywords

none

Package Sidebar

Install

npm i diff-stream2

Weekly Downloads

138

Version

1.0.4

License

MIT

Last publish

Collaborators

  • jed