hypercore-storage 1.1.1 → 1.1.3
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 +6 -2
- package/lib/block-dependency-stream.js +15 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -240,14 +240,18 @@ class HypercoreStorage {
|
|
|
240
240
|
const d = this.core.dependencies[i]
|
|
241
241
|
|
|
242
242
|
if (dep !== null && d.length > dep.length) {
|
|
243
|
-
|
|
243
|
+
if (d.dataPointer !== dep.dataPointer) {
|
|
244
|
+
deps.push({ dataPointer: d.dataPointer, length: dep.length })
|
|
245
|
+
}
|
|
244
246
|
return deps
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
deps.push(d)
|
|
248
250
|
}
|
|
249
251
|
|
|
250
|
-
if (dep !== null
|
|
252
|
+
if (dep !== null && (deps.length === 0 || deps[deps.length - 1].dataPointer !== dep.dataPointer)) {
|
|
253
|
+
deps.push(dep)
|
|
254
|
+
}
|
|
251
255
|
return deps
|
|
252
256
|
}
|
|
253
257
|
|
|
@@ -25,8 +25,7 @@ module.exports = class BlockStream extends Readable {
|
|
|
25
25
|
if (this._consumed > this.core.dependencies.length) return
|
|
26
26
|
|
|
27
27
|
const deps = this.core.dependencies
|
|
28
|
-
|
|
29
|
-
const index = findDependencyIndex(deps, this.end, this._consumed++, this.reverse)
|
|
28
|
+
const index = this._findDependencyIndex(deps)
|
|
30
29
|
|
|
31
30
|
const curr = deps[index]
|
|
32
31
|
const prev = deps[index - 1]
|
|
@@ -38,6 +37,19 @@ module.exports = class BlockStream extends Readable {
|
|
|
38
37
|
this._makeStream(core.block(ptr, start), core.block(ptr, end))
|
|
39
38
|
}
|
|
40
39
|
|
|
40
|
+
_findDependencyIndex (deps) {
|
|
41
|
+
if (!this.reverse) return this._consumed++
|
|
42
|
+
|
|
43
|
+
let i = deps.length - this._consumed++
|
|
44
|
+
while (i > 0) {
|
|
45
|
+
if (deps[i - 1].length <= this.end) return i
|
|
46
|
+
i--
|
|
47
|
+
this._consumed++
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
_predestroy () {
|
|
42
54
|
if (this._stream !== null) this._stream.destroy()
|
|
43
55
|
}
|
|
@@ -83,7 +95,7 @@ module.exports = class BlockStream extends Readable {
|
|
|
83
95
|
// empty the current stream
|
|
84
96
|
if (this._onreadable() === true) this._drained = true
|
|
85
97
|
|
|
86
|
-
this._stream =
|
|
98
|
+
this._stream = null
|
|
87
99
|
|
|
88
100
|
this._update()
|
|
89
101
|
this._maybeDrain()
|
|
@@ -98,13 +110,3 @@ module.exports = class BlockStream extends Readable {
|
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
function noop () {}
|
|
101
|
-
|
|
102
|
-
function findDependencyIndex (deps, end, offset, reverse) {
|
|
103
|
-
if (!reverse) return offset
|
|
104
|
-
|
|
105
|
-
for (let i = deps.length - offset; i > 0; i--) {
|
|
106
|
-
if (deps[i - 1].length <= end) return i
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return 0
|
|
110
|
-
}
|