@hyperswarm/replicator
Replicate data structures easily using hyperswarm
Install
npm install @hyperswarm/replicator
Usage
You data structure has to support a .replicate() stream, then you can replicate
them using the hyperswarm replicator.
const Replicator = require('@hyperswarm/replicator')
const r = new Replicator()
r.add(aHypercore, {
live: true
})
API
r = new Replicator([options])
Make a new replicator. Options include:
{
bootstrap: [...],
}
promise = r.add(hyperDataStructure, [options])
Add a hyper* data structure to replicate.
{
live: bool,
upload: bool,
download: bool,
encrypt: bool,
discoveryKey: <buf>,
announce: true,
lookup: true,
keyPair: { publicKey, secretKey },
onauthenticate (remotePublicKey, done)
}
Promise resolves when the data structure has been fully added.
promise = r.remove(hyperDataStructure)
Remove a data structure from replication.
Promise resolves when the data structure has been fully removed.
r.swarm
The associated hyperswarm instance.
r.on('discovery-key', (discoveryKey, remoteStream) => ...)
Emitted when a remote asks for a discovery key of a data structure you are
not currently replicating.
r = Replicator.replicate(hyperDataStructure[s])
Easy "one off" replication of one or more data structures.
License
MIT