2.0.2 • Published 3 years ago

@hyperswarm/replicator v2.0.2

Weekly downloads
21
License
MIT
Repository
github
Last release
3 years ago

@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 // passed to .replicate
})

API

r = new Replicator([options])

Make a new replicator. Options include:

{
  bootstrap: [...], // optional set the DHT bootstrap servers
}

promise = r.add(hyperDataStructure, [options])

Add a hyper* data structure to replicate.

{
  live: bool, // passed to .replicate
  upload: bool, // passed to .replicate
  download: bool, // passed to .replicate
  encrypt: bool, // passed to .replicate
  discoveryKey: <buf>, // optionally set your own discovery key
  announce: true, // should the swarm announce you?
  lookup: true, // should the swarm do lookups for you?
  keyPair: { publicKey, secretKey }, // noise keypair used for the connection
  onauthenticate (remotePublicKey, done) // the onauthenticate hook to verify remote key pairs
}

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

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.0

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago