JSPM

@web4/mountable-bittrie

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q30752F
  • License MIT

A Bittrie wrapper that supports mounting of other Bittries

Package Exports

  • @web4/mountable-bittrie
  • @web4/mountable-bittrie/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@web4/mountable-bittrie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@web4/mountable-bittrie

A Bittrie wrapper that supports mounting of sub-Bittries.

Usage

A MountableBittrie can be mounted within another MountableBittrie by using the mount command:

const store = chainstore(ram)
const trie1 = new MountableBittrie(store)
const trie2 = new MountableBittrie(store)

trie2.ready(() => {
  trie1.mount('/a', trie2.key, ...)
})

Assuming trie2 has a value 'hello' at /b/c:

trie1.get('/a/b/c', console.log) // Will return Buffer.from('hello')

A mount can be removed by performing a del on the mountpoint :

trie1.del('/a', err => {
  trie1.get('/a/b/c', console.log) // Will print `null`
})

API

mountable-bittrie re-exposes the bittrie API, with the addition of the following methods (and a different constructor):

const trie = new MountableBittrie(chainstore, key, opts)

  • chainstore: any object that implements the chainstore interface. For now, it's recommanded to use random-access-chainstore
  • key is the bittrie key
  • opts can contain any bittrie options

trie.mount(path, key, opts, cb)

  • path is the mountpoint
  • key is the key for the MountableBittrie to be mounted at path

opts can include:

{
  remotePath: '/remote/path', // An optional base path within the mount.
  version: 1                  // An optional checkout version
}

Note: We're still adding support for many bittrie methods. Here's what's been implemented so far:

  • get
  • put
  • del
  • batch
  • iterator
  • list
  • createReadStream
  • createWriteStream
  • checkout
  • watch
  • createHistoryStream
  • createDiffStream

License

MIT