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

multifeed-storage

v1.1.2

Published

storage, opening, and closing of a set of hypercores

Downloads

5

Readme

multifeed-storage

store hypercore feeds and load feeds by local name or discovery key

example

var Storage = require('multifeed-storage')
var raf = require('random-access-file')
var path = require('path')
require('mkdirp').sync('/tmp/multifeed-storage')

var s = Storage(function (name) {
  return raf(path.join('/tmp/multifeed-storage', name))
})
s.createLocal('hello', function (err, feed) {
  if (err) return console.error(err)

  s.fromDiscoveryKey(feed.discoveryKey, function (err, key) {
    // key === feed.key
    console.log('from discovery key:', key.toString('hex'))
  })
  s.fromLocalName('hello', function (err, key) {
    // key === feed.key
    console.log('from local name:', key.toString('hex'))
  })
  // append data, close the feed, and open it again with get():
  feed.append('whatever', function (err) {
    s.close(feed.key)
    s.get(feed.key, function (err, feed1) {
      if (err) console.error(err)
      else feed1.get(0, console.log)
    })
  })
})

api

var Storage = require('multifeed-storage')

var store = new Storage(storeFn, opts)

Create a new multifeed-storage instance store from a storage function storeFn and opts:

  • opts.delete(path, cb) - implementation to recursively delete paths This is used by store.delete(id, cb) to remove all data associated with a feed.

store.fromDiscoveryKey(discoveryKey, cb)

Find the public key for a managed feed by its discovery key as cb(err, key).

key is a Buffer like feed.key.

store.fromLocalName(localName, cb)

Find the public key for a string name localName as cb(err, key).

key is a Buffer like feed.key.

store.createLocal(localName, opts, cb)

Create a "local" hypercore feed from an optional localName, opts (passed to hypercore's constructor), as cb(err, feed) called after feed metadata has been written to internal storage and the feed is ready.

"Local" hypercores are feeds where the secret key is stored locally and the local machine may append messages. A new keypair is created when createLocal() is called.

Emits the 'create-local' event with the feed.

store.createRemote(key, opts, cb)

Create a "remote" hypercore feed from a hex string or buffer key, opts (passed to hypercore's constructor), as cb(err, feed) called after feed metadata has been written to internal storage and the feed is ready.

"Remote" hypercores are feeds where the secret key is not stored locally and the local machine may not append messages. Use this method to sync a feed created on a remote machine.

Emits the 'create-remote' event with the feed.

store.get(id, opts, cb)

Load a hypercore by its id: either a 32-byte buffer or hex string or a local name string as cb(err, feed). opts are passed along to the hypercore constructor.

If this feed is already open, you will get the opened instance, which may have been created with different hypercore options than the opts you specify.

If a feed is opened (not cached), the 'open' event will fire with the feed.

store.has(key, cb)

Determine whether the store has a feed with key as cb(err, hasFeed) for a boolean hasFeed.

store.hasLocal(localname, cb)

Determine whether the store has a feed with a localname as cb(err, hasFeed) for a boolean hasFeed.

store.getOrCreateRemote(key, opts, cb)

Load a feed as cb(err, feed) from a key or if the key doesn't exist, create it as a "remote" feed (see the createRemote api docs for more info).

An 'open' or 'create-remote' event may be fired.

store.getOrCreateLocal(localName, opts, cb)

Load a feed as cb(err, feed) from a key or if the key doesn't exist, create it as a "local" feed (see the createLocal api docs for more info).

An 'open' or 'create-local' event may be fired.

store.isOpen(key)

Return a boolean: whether the feed identified by key is open or not.

store.close(key, cb)

Close the feed with key.

Emits the 'close' event with the feed.

store.closeAll(cb)

Close all open feeds.

Emits the 'close' event for each open feed.

store.delete(key, cb)

Close and delete all files associated with the feed key.

For this to work you must specify an opts.delete implementation to the constructor.

Emits the 'delete' event with the feed key as a Buffer.

store.on('create-local', function (feed) {})

Emitted when a new local feed is created.

store.on('create-remote', function (feed) {})

Emitted when a new remote feed is created.

store.on('open', function (feed) {})

Emitted when a feed is opened that was not already cached.

store.on('close', function (feed) {})

Emitted when an open feed is closed.

store.on('delete', function (key) {})

Emitted when a feed is deleted with the feed key (Buffer).