hypercore-storage 1.1.1 → 1.1.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.
- package/lib/block-dependency-stream.js +15 -13
- package/package.json +1 -1
|
@@ -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
|
-
}
|