hypercore-storage 1.1.4 → 1.1.5
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 +27 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -86,29 +86,42 @@ class HypercoreStorage {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// TODO: this might have to be async if the dependents have changed, but prop ok for now
|
|
89
|
-
updateDependencyLength (length) {
|
|
89
|
+
updateDependencyLength (length, truncated) {
|
|
90
90
|
const deps = this.core.dependencies
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const i = this.findDependencyIndex(length, truncated)
|
|
93
|
+
if (i === -1) throw new Error('Dependency not found')
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
this.core = {
|
|
96
|
+
corePointer: this.core.corePointer,
|
|
97
|
+
dataPointer: this.core.dataPointer,
|
|
98
|
+
dependencies: deps.slice(0, i + 1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (this.core.dependencies[i].length !== length) {
|
|
102
|
+
this.core.dependencies[i] = {
|
|
103
|
+
dataPointer: deps[i].dataPointer,
|
|
104
|
+
length
|
|
99
105
|
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
100
108
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
findDependencyIndex (length, truncated) {
|
|
110
|
+
const deps = this.core.dependencies
|
|
111
|
+
|
|
112
|
+
if (truncated) {
|
|
113
|
+
for (let i = 0; i < deps.length; i++) {
|
|
114
|
+
if (deps[i].length >= length) return i
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
return
|
|
117
|
+
return -1
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (let i = deps.length - 1; i >= 0; i--) {
|
|
121
|
+
if (deps[i].length <= length) return i
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
|
|
124
|
+
return -1
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
get snapshotted () {
|