hypercore-storage 0.0.31 → 0.0.32
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 +28 -1
- package/lib/memory-overlay.js +4 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -489,7 +489,34 @@ class HypercoreStorage {
|
|
|
489
489
|
|
|
490
490
|
snapshot () {
|
|
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) s.dependencies.push(dep)
|
|
495
|
+
|
|
496
|
+
return s
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
findDependency (length) {
|
|
500
|
+
for (let i = this.dependencies.length - 1; i >= 0; i--) {
|
|
501
|
+
const dep = this.dependencies[i]
|
|
502
|
+
if (dep.length < length) return dep
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return null
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
updateDependencies (length) {
|
|
509
|
+
const deps = this.dependencies
|
|
510
|
+
|
|
511
|
+
for (let i = deps.length - 1; i >= 0; i--) {
|
|
512
|
+
if (deps[i].length < length) {
|
|
513
|
+
deps[i].length = length
|
|
514
|
+
this.dependencies = deps.slice(0, i + 1)
|
|
515
|
+
return
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
throw new Error('Dependency not found')
|
|
493
520
|
}
|
|
494
521
|
|
|
495
522
|
createReadBatch (opts) {
|
package/lib/memory-overlay.js
CHANGED