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

random-access-corestore

v0.9.3

Published

A simple corestore that wraps a random-access-storage module

Downloads

6

Readme

random-access-corestore

Build Status

A simple corestore that wraps a random-access-storage module. This module is the canonical implementation of the "corestore" interface, which exposes a hypercore factory and a set of associated functions for managing generated hypercores.

Corestore imposes the convention that the first requested hypercore defines the discovery key (and encryption parameters) for its replication stream.

Installation

npm i random-access-corestore --save

Usage

A random-access-corestore instance can be constructed with either a random-access-storage module, or a function that returns a random-access-storage module given a path:

const corestore = require('random-access-corestore')
const ram = require('random-access-memory')
const raf = require('random-access-file')
const store1 = corestore(ram)
const store2 = corestore(path => raf('store2/' + path))

Hypercores can be generated with get. The first core that's generated will be considered the "main" core, and will define the corestore's replication parameters:

const core1 = store1.get()

Additional hypercores can be created either by key or by name. If a hypercore is created by name, it will be stored as such in the storage layer (e.g. in the second directory). Named hypercores are useful when instantiating a new hypercore-based data structure and the hypercore keys have not yet been generated:

const core2 = store1.get({ name: 'second' })

Once a named hypercore has been instantiated, it's indexed by both its key and its discovery key in memory, so that it can be injected into replication streams.

Two corestores can be replicated with the replicate function, which accepts hypercore's replicate options:

const store2 = corestore(ram)
const core3 = store2.get(core1.key)
const stream = store1.replicate()
stream.pipe(store2.replicate()).pipe(stream)

API

const store = corestore(storage)

Create a new corestore instance. storage can be either a random-access-storage module, or a function that takes a path and returns a random-access-storage instance.

store.get(opts)

Create a new hypercore. Options can be one of the following:

{
  key: 0x1232..., // A Buffer representing a hypercore key
  discoveryKey: 0x1232... // A Buffer representing a hypercore discovery key (must have been previously created by key)
  name: 'core-name', // A name for the new hypercore, if the key has not yet been generated
  ...opts // All other options accepted by the hypercore constructor
}

If opts is a Buffer, it will be interpreted as a hypercore key.

store.on('feed', feed, options)

Emitted everytime a feed is loaded internally (ie, the first time get(key) is called). Options will be the full options map passed to .get.

store.replicate(opts)

Create a replication stream for all generated hypercores. The stream's handshake parameters (i.e. its discovery key) will be defined by the first hypercore created by the corestore.

opts can be any hypercore replication options.

store.close(cb)

Close all hypercores previously generated by the corestore.

License

MIT