npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

append-tree

v2.4.4

Published

Model a tree structure on top of an append-only log.

Downloads

553

Readme

append-tree

Model a tree structure on top of an append-only log.

npm install append-tree

Build Status

The data structure stores a small index for every entry in the log, meaning no external indexing is required to model the tree. Also means that you can perform fast lookups on sparsely replicated logs.

Usage

var tree = require('append-tree')
var hypercore = require('hypercore')

var feed = hypercore('./my-tree')
var tr = tree(feed, {valueEncoding: 'utf-8'})

tr.put('/hello', 'world', function (err) {
  if (err) throw err

  tr.get('/hello', function (err, val) {
    if (err) throw err
    console.log(val) // <-- 'world'

    tr.list('/', function (err, list) {
      if (err) throw err
      console.log(list) // <-- ['hello']
    })
  })
})

API

var tr = tree(feed, [options])

Create a new append tree.

First option should be a hypercore feed (or any append-only log that supports .append() and .length).

Options include:

{
  valueEncoding: 'binary' | 'utf-8' | 'json' | anyAbstractEncoding
  offset: 0 // optional feed offset where the tree starts
  cache: true // use an LRU cache on tree entries
  cacheSize: 65536 // how many entries to use in the LRU cache
}

tr.put(name, value, [callback])

Insert a new node in the tree.

tr.del(name, [callback])

Delete a node from the tree.

tr.get(name, [options], callback)

Retrieve a value from the tree. Accepts the same options as hypercore's get method.

tr.list(name, [options], callback)

List all immediate children of a node. Similar to doing a readdir in a file system. Accepts the same options as hypercore's get method.

tr.path(name, [options], callback)

Will call the callback with a list of feed indexes needed to lookup the given name. Useful if you are replicating the tree and want to avoid roundtrips. Accepts the same options as hypercore's get method.

var stream = tr.history([options])

Create a history stream containing all the changes in the tree. Accepts the same options as hypercore's createReadStream method.

Each data event looks like this

{
  type: 'put' | 'del',
  version: 42, // version of the tree at this point in time
  name: '/foo',
  value: new Buffer('bar') // null if it is a del
}

tr.version

Number describing the current version of the tree.

Populated initially after ready event. Will be -1 before.

tr.on('ready', cb)

Fired when the tree is ready and all properties have been populated.

var oldTree = tr.checkout(version, [options])

Checkout an old readonly version of the tree. .get, .list will return the same values as the tree did at the old version. Accepts the same options as the tree constructor.

var stream = tr.diff(checkout, [options])

Diff a tree against another checkout of the tree. Will emit the same data as the history stream but representing the diff from tr to checkout.

Accepts the same options as hypercore's createReadStream method.

License

MIT