Track upload/download progress of a hypercore replication stream.
Track the sync progress of a non-sparse non-live hypercore replication stream.
This module lets you wrap a hypercore
N.B. Designed for hypercore@8
N.B. This should give accurate download and upload progress when sparse mode is off. However, when using sparse mode, download progress should remain accurate, but upload progress can be inaccurate. This is due to how the hypercore protocol works: the remote peer doesn't have to explicitly name the blocks it wants -- it can provide a range of wants that may include blocks it already possesses. Live streams aren't yet supported either.
var progress = require('hypercore-progress')
var ram = require('random-access-memory')
var hypercore = require('hypercore')
var pump = require('pump')
var core1 = hypercore(ram, {valueEncoding:'json'})
core1.ready(() => {
core1.append([
'ichi',
'ni',
'san',
], () => {
var core2 = hypercore(ram, core1.key, {valueEncoding:'json'})
core2.ready(() => {
sync()
})
})
})
function sync () {
var r1 = core1.replicate(true)
progress(core1, r1).on('progress', (status) => {
console.log('core1', status)
})
var r2 = core2.replicate(false)
progress(core2, r2).on('progress', (status) => {
console.log('core1', status)
})
pump(r1, r2, r1, err => {
console.log('done')
})
})
outputs
core1 { up: { sofar: 1, total: 3 }, down: { sofar: 0, total: 0 } }
core2 { up: { sofar: 0, total: 0 }, down: { sofar: 1, total: 3 } }
core1 { up: { sofar: 2, total: 3 }, down: { sofar: 0, total: 0 } }
core2 { up: { sofar: 0, total: 0 }, down: { sofar: 2, total: 3 } }
core1 { up: { sofar: 3, total: 3 }, down: { sofar: 0, total: 0 } }
core2 { up: { sofar: 0, total: 0 }, down: { sofar: 3, total: 3 } }
done
var progress = require('hypercore-progress')
Wraps a hypercore and a particular
hypercore-protocol
stream
and tracks upload and download progress of the hypercores it is replicating.
Emitted when a chunk is downloaded or uploaded.
state
will be of the shape
{
up: { sofar: 5, total: 12 },
down: { sofar: 1, total: 3 }
}
With npm installed, run
$ npm install hypercore-progress
This module makes some assumptions:
MIT