hypercore-storage 0.0.31 → 0.0.33
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 +34 -2
- package/lib/memory-overlay.js +4 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -487,9 +487,41 @@ class HypercoreStorage {
|
|
|
487
487
|
return new MemoryOverlay(this)
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
snapshot () {
|
|
490
|
+
snapshot (sharedLength = -1) {
|
|
491
491
|
assert(this.destroyed === false)
|
|
492
|
-
|
|
492
|
+
const s = new HypercoreStorage(this.root, this.discoveryKey, this.corePointer, this.dataPointer, this.db.snapshot())
|
|
493
|
+
|
|
494
|
+
for (const dep of this.dependencies) {
|
|
495
|
+
const length = sharedLength !== -1 && sharedLength < dep.length ? sharedLength : dep.length
|
|
496
|
+
s.dependencies.push({ data: dep.data, length })
|
|
497
|
+
|
|
498
|
+
if (length === sharedLength) break
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
return s
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
findDependency (length) {
|
|
505
|
+
for (let i = this.dependencies.length - 1; i >= 0; i--) {
|
|
506
|
+
const dep = this.dependencies[i]
|
|
507
|
+
if (dep.length < length) return dep
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return null
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
updateDependencies (length) {
|
|
514
|
+
const deps = this.dependencies
|
|
515
|
+
|
|
516
|
+
for (let i = deps.length - 1; i >= 0; i--) {
|
|
517
|
+
if (deps[i].length < length) {
|
|
518
|
+
deps[i].length = length
|
|
519
|
+
this.dependencies = deps.slice(0, i + 1)
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
throw new Error('Dependency not found')
|
|
493
525
|
}
|
|
494
526
|
|
|
495
527
|
createReadBatch (opts) {
|
package/lib/memory-overlay.js
CHANGED