hypercore-storage 1.7.0 → 1.8.0

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.
package/index.js CHANGED
@@ -101,6 +101,30 @@ class HypercoreStorage {
101
101
  return null
102
102
  }
103
103
 
104
+ updateSnapshotHead (dep) {
105
+ const deps = this.core.dependencies
106
+
107
+ for (let i = deps.length - 1; i >= 0; i--) {
108
+ const d = deps[i]
109
+
110
+ if (d.dataPointer !== dep.dataPointer) continue
111
+
112
+ // check if nothing changed
113
+ if (d.length === dep.length && i === deps.length - 1) return
114
+
115
+ this.core = {
116
+ corePointer: this.core.corePointer,
117
+ dataPointer: this.core.dataPointer,
118
+ dependencies: deps.slice(0, i + 1)
119
+ }
120
+
121
+ this.core.dependencies[i] = {
122
+ dataPointer: dep.dataPointer,
123
+ length: dep.length
124
+ }
125
+ }
126
+ }
127
+
104
128
  // TODO: this might have to be async if the dependents have changed, but prop ok for now
105
129
  updateDependencyLength (length, truncated) {
106
130
  const deps = this.core.dependencies
@@ -27,11 +27,12 @@ module.exports = class BlockStream extends Readable {
27
27
  const deps = this.core.dependencies
28
28
  const index = this._findDependencyIndex(deps)
29
29
 
30
- const curr = deps[index]
31
- const prev = deps[index - 1]
30
+ const curr = index < deps.length ? deps[index] : null
31
+ const prev = (index > 0 && index - 1 < deps.length) ? deps[index - 1] : null
32
+
33
+ const start = (prev && prev.length > this.start) ? prev.length : this.start
34
+ const end = (curr && (this.end === -1 || curr.length < this.end)) ? curr.length : this.end
32
35
 
33
- const start = prev && prev.length > this.start ? prev.length : this.start
34
- const end = curr && curr.length < this.end ? curr.length : this.end
35
36
  const ptr = curr ? curr.dataPointer : this.core.dataPointer
36
37
 
37
38
  this._makeStream(core.block(ptr, start), core.block(ptr, end))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",