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.
@@ -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 index = this.reverse ? this.core.dependencies.length - this._consumed : this._consumed
27
- const offset = index === 0 ? 0 : this.core.dependencies[index - 1].length
27
+ const deps = this.core.dependencies
28
28
 
29
- let end = 0
30
- let ptr = 0
29
+ const index = findDependencyIndex(deps, this.end, this._consumed++, this.reverse)
31
30
 
32
- if (this._consumed < this.core.dependencies.length) {
33
- const dep = this.core.dependencies[this._consumed]
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
- if (end === offset) return
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, offset), core.block(ptr, end))
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
@@ -16,6 +16,7 @@ const CORE_HINTS = schema.getEncoding('@core/hints')
16
16
 
17
17
  class CoreTX {
18
18
  constructor (core, db, view, changes) {
19
+ if (db.snapshotted) throw new Error('Cannot open core tx on snapshot')
19
20
  this.core = core
20
21
  this.db = db
21
22
  this.view = view
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",