Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created June 10, 2013 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/5748161 to your computer and use it in GitHub Desktop.
Save dominictarr/5748161 to your computer and use it in GitHub Desktop.
var level = require('level')
var sublevel = require('sublevel')
var db = sublevel(level(path))
var Merkle = require('level-merkle')
var treeDb = Merkle(db, 'merkle')
treeDb.topHash(function (err, hash) {
//get the top hash
})
var ts = treeDb.createTreeStream() //stream the hashes from the top to the leaves
var ts2 = tree2Db.createTreeStream()
//extract the difference between two trees?
var ms = Merkle.difference(ts, ts2)
//retrive the differences so you can send them
//pull(a,b,c) is the same as a.pipe(b).pipe(c)
//in the new pull streams.
pull(
ms,
pull.asyncMap(function (hash, cb) {
treeDb.get(hash, cb)
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment