Fix `info.key`, `info.discoveryKey`, and `info.fork`
MODIFY
index.js
index.js
@@ -616,7 +616,7 @@ module.exports = class Hypercore extends EventEmitter {
async info () {
if (this.opened === false) await this.opening
- return Info.from(this.core, this.padding, this._snapshot)
+ return Info.from(this)
}
async update (opts) {

MODIFY
lib/info.js
lib/info.js
module.exports = class Info {
constructor (opts = {}) {
+ this.key = opts.key
+ this.discoveryKey = opts.discoveryKey
this.length = opts.length || 0
this.contiguousLength = opts.contiguousLength || 0
this.byteLength = opts.byteLength || 0
+ this.fork = opts.fork || 0
this.padding = opts.padding || 0
}
- static async from (core, padding, snapshot) {
+ static async from (session) {
return new Info({
- key: core.key,
- discoveryKey: core.discoveryKey,
- length: snapshot
- ? snapshot.length
- : core.tree.length,
- contiguousLength: core.header.contiguousLength,
- byteLength: snapshot
- ? snapshot.byteLength
- : (core.tree.byteLength - (core.tree.length * padding)),
- fork: core.tree.fork,
- padding
+ key: session.key,
+ discoveryKey: session.discoveryKey,
+ length: session.length,
+ contiguousLength: session.contiguousLength,
+ byteLength: session.byteLength,
+ fork: session.fork,
+ padding: session.padding
})
}
}

Fix `info.key`, `info.discoveryKey`, and `info.fork` (#317)