hypercore 10.31.0 → 10.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/batch.js +5 -4
  2. package/package.json +1 -1
package/lib/batch.js CHANGED
@@ -70,9 +70,8 @@ module.exports = class HypercoreBatch extends EventEmitter {
70
70
  if (this.opened) return
71
71
 
72
72
  if (this._checkoutLength !== -1) {
73
- const batch = await this.session.core.tree.truncate(this._checkoutLength, this.session.fork)
74
- batch.upgraded = false
75
- batch.treeLength = batch.ancestors = this._checkoutLength
73
+ const batch = await this.session.core.tree.restoreBatch(this._checkoutLength)
74
+ batch.treeLength = this._checkoutLength
76
75
  if (this.opened) return
77
76
  this._sessionLength = batch.length
78
77
  this._sessionByteLength = batch.byteLength
@@ -82,6 +81,7 @@ module.exports = class HypercoreBatch extends EventEmitter {
82
81
 
83
82
  if (last > this.session.length) {
84
83
  const batch = await this.session.core.tree.restoreBatch(last)
84
+ if (this.opened) return
85
85
  this._sessionLength = batch.length
86
86
  this._sessionByteLength = batch.byteLength - this.session.padding * batch.length
87
87
  this._sessionBatch = batch
@@ -185,6 +185,7 @@ module.exports = class HypercoreBatch extends EventEmitter {
185
185
 
186
186
  async restoreBatch (length) {
187
187
  if (this.opened === false) await this.opening
188
+ if (length >= this._sessionLength) return this.createTreeBatch(length)
188
189
  return this.session.core.tree.restoreBatch(length)
189
190
  }
190
191
 
@@ -355,7 +356,7 @@ module.exports = class HypercoreBatch extends EventEmitter {
355
356
  if (info === null) return false
356
357
 
357
358
  const delta = info.byteLength - this._sessionByteLength
358
- const newBatch = info.length !== this.session.length ? await this.restoreBatch(info.length) : this.session.createTreeBatch()
359
+ const newBatch = info.length !== this.session.length ? await this.session.core.tree.restoreBatch(info.length) : this.session.createTreeBatch()
359
360
 
360
361
  this._sessionLength = info.length
361
362
  this._sessionByteLength = info.byteLength
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.31.0",
3
+ "version": "10.31.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {