hypercore-storage 1.0.5 → 1.0.6
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 +19 -16
- package/lib/tx.js +1 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ module.exports = class BlockStream extends Readable {
|
|
|
8
8
|
this.core = core
|
|
9
9
|
this.db = db
|
|
10
10
|
this.updates = updates
|
|
11
|
+
this.start = start
|
|
11
12
|
this.end = end
|
|
12
13
|
this.reverse = reverse === true
|
|
13
14
|
|
|
@@ -23,26 +24,18 @@ module.exports = class BlockStream extends Readable {
|
|
|
23
24
|
_update () {
|
|
24
25
|
if (this._consumed > this.core.dependencies.length) return
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
const offset = index === 0 ? 0 : this.core.dependencies[index - 1].length
|
|
27
|
+
const deps = this.core.dependencies
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
let ptr = 0
|
|
29
|
+
const index = findDependencyIndex(deps, this.end, this._consumed++, this.reverse)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
end = this.end === -1 ? dep.length : Math.min(this.end, dep.length)
|
|
35
|
-
ptr = dep.dataPointer
|
|
36
|
-
} else {
|
|
37
|
-
end = this.end === -1 ? Infinity : this.end
|
|
38
|
-
ptr = this.core.dataPointer
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this._consumed++
|
|
31
|
+
const curr = deps[index]
|
|
32
|
+
const prev = deps[index - 1]
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
const start = prev && prev.length > this.start ? prev.length : this.start
|
|
35
|
+
const end = curr && curr.length < this.end ? curr.length : this.end
|
|
36
|
+
const ptr = curr ? curr.dataPointer : this.core.dataPointer
|
|
44
37
|
|
|
45
|
-
this._makeStream(core.block(ptr,
|
|
38
|
+
this._makeStream(core.block(ptr, start), core.block(ptr, end))
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
_predestroy () {
|
|
@@ -105,3 +98,13 @@ module.exports = class BlockStream extends Readable {
|
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
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
|
+
}
|
package/lib/tx.js
CHANGED