https://github.com/little-core-labs/hypercore-replicate
A simple function to replicate multiple hypercores.
https://github.com/little-core-labs/hypercore-replicate
hypercore replicate util
Last synced: 4 months ago
JSON representation
A simple function to replicate multiple hypercores.
- Host: GitHub
- URL: https://github.com/little-core-labs/hypercore-replicate
- Owner: little-core-labs
- License: mit
- Created: 2019-05-06T18:28:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T18:26:01.000Z (about 6 years ago)
- Last Synced: 2025-01-05T04:06:47.661Z (about 1 year ago)
- Topics: hypercore, replicate, util
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 7
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
hypercore-replicate
===================
A simple function to replicate multiple hypercores.
## Installation
```sh
$ npm install hypercore-replicate
```
## Usage
```js
const replicate = require('hypercore-replicate')
replicate(...hypercores, opts, callback)
```
## Example
```js
const replicate = require('hypercore-replicate')
const hypercore = require('hypercore')
const ram = require('random-access-memory')
const feed = hypercore(ram)
feed.ready(() => {
const copy = hypercore(ram, feed.key)
const other = hypercore(ram, feed.key)
replicate(feed, copy, other.replicate(), { live: true })
feed.append('hello')
copy.update(() => copy.head(console.log)) // 'null '
other.update(() => other.head(console.log)) // 'null '
})
```
## API
### `stream = replicate(...hypercores, opts, onend)`
Replicate a variable amount of hypercores that share the same key with each
other where `opts` is passed to `hypercores[i].relicate(opts)` and
`onend` is called when all the replication streams have ended.
## License
MIT