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

hypercore-rehoster

v1.2.1

Published

Help keep the hypercores of your choice available

Downloads

79

Readme

Hypercore Rehoster

Help host the hypercores of your choice.

For a hypercore containing a hyperdrive, both underlying cores will be served.

If you rehost another rehoster, you will rehost all its cores as well (recursively).

See hypercore-rehost-server for a server wrapping the rehoster, and hypercore-rehost-cli for a CLI to interact with that server.

Description

The rehoster automatically keeps the cores it hosts up to date, by continuously listening for changes in the background.

The rehoster is recursive: if you rehost the key of another rehoster, you will automatically also rehost all the cores contained in that rehoster (and if those also contain rehoster keys, you will host their cores as well, recursively).

It is possible to turn a normal Hyperbee into a rehoster by adding keys to the sub at Rehoster.SUB. See the Usage section.

Rehosters can host one other, in which case they will host the union of all their individual cores.

Install

npm i hypercore-rehoster

API

const rehoster = new Rehoster(corestore, swarmManager, { bee, beeName })

Initialises a rehoster.

The corestore is managed by the rehoster (closes when the rehoster closes), but the swarmManager is not.

If a bee is passed, that bee will be used as database. If not, the bee will be opened from the corestore, based on the beeName (or the default name if none is provided).

Note when passing a bee: to be able to add/delete cores, the corestore should have write rights on the bee (it should have been created with that corestore).

Rehoster.SUB

A special Hyperbee sub identifier which the rehoster watches. If Hypercore keys are added there, then those will be rehosted too.

This allows arbitrary Hyperbees to behave as a rehoster.

await rehoster.ready()

Set up the the rehoster, so it starts downloading and serving all the keys it contains.

await rehoster.add(key)

Add a new key to be rehosted (any valid key format can be used).

Note that connecting with other peers and downloading the core's content happens in the background, so not all content is immediately rehosted after add finishes.

await rehoster.delete(key)

Remove a key.

Note that propagating the delete to recursively hosted cores happens in the background (so a sub-rehoster's cores will not yet be unhosted immediately after delete finishes)

await rehoster.close()

Close the rehoster, and clean up.

Usage

See example.js for the basic usage.

To make an existing Hyperbee behave as a rehoster, you can add keys to the sub at Rehoster.SUB:

const core = new Hypercore(...)
const bee = new Hyperbee(...)
const sub = bee.sub(Rehoster.SUB)
await sub.put(core.key)
// The core will now be rehosted whenever the bee is