hypercore-storage 0.0.38 → 0.0.40

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
@@ -152,7 +152,7 @@ class WriteBatch {
152
152
  const s = encodeDataIndex(this.storage.dataPointer, type, start)
153
153
  const e = encodeDataIndex(this.storage.dataPointer, type, end === -1 ? Infinity : end)
154
154
 
155
- return this.write.deleteRange(s, e)
155
+ return this.write.tryDeleteRange(s, e)
156
156
  }
157
157
 
158
158
  destroy () {
@@ -117,7 +117,7 @@ class MemoryOverlay {
117
117
  this.snapshotted = false
118
118
  this.snapshotShared = null
119
119
  this.activeSnapshots = 0
120
- this.copyOnWrite = false
120
+ this.copied = false
121
121
  }
122
122
 
123
123
  async registerBatch (name, length, overwrite) {
@@ -128,7 +128,6 @@ class MemoryOverlay {
128
128
  if (this.snapshotShared !== null) return this.snapshotShared.snapshot()
129
129
 
130
130
  this.activeSnapshots++
131
- this.copyOnWrite = true
132
131
 
133
132
  const snap = new MemoryOverlay(this.storage.snapshot())
134
133
 
@@ -150,7 +149,8 @@ class MemoryOverlay {
150
149
  }
151
150
 
152
151
  _copy () {
153
- this.copyOnWrite = false
152
+ if (this.copied) return
153
+ this.copied = true
154
154
 
155
155
  // clone state
156
156
  if (this.head !== null) this.head = Object.assign(this.head)
@@ -179,7 +179,7 @@ class MemoryOverlay {
179
179
  }
180
180
 
181
181
  createWriteBatch () {
182
- if (this.copyOnWrite) this._copy()
182
+ if (this.activeSnapshots > 0) this._copy()
183
183
  return new MemoryOverlayWriteBatch(this)
184
184
  }
185
185
 
@@ -222,7 +222,7 @@ class MemoryOverlay {
222
222
  destroy () {
223
223
  if (this.snapshotted) this.storage.destroy()
224
224
  if (this.snapshotShared === null) return
225
- if (--this.snapshotShared.activeSnapshots === 0) this.snapshotShared.copyOnWrite = false
225
+ this.snapshotShared.activeSnapshots--
226
226
  this.snapshotShared = null
227
227
  }
228
228
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",