hypercore 10.31.8 → 10.31.10
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/lib/core.js +12 -0
- package/lib/remote-bitfield.js +6 -1
- package/lib/streams.js +1 -1
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -230,6 +230,8 @@ module.exports = class Core {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
try {
|
|
233
|
+
const updates = []
|
|
234
|
+
|
|
233
235
|
let pos = 0
|
|
234
236
|
|
|
235
237
|
while (pos < length) {
|
|
@@ -252,6 +254,12 @@ module.exports = class Core {
|
|
|
252
254
|
this.bitfield.setRange(segmentStart, segmentEnd - segmentStart, true)
|
|
253
255
|
|
|
254
256
|
pos = segmentEnd + 1
|
|
257
|
+
|
|
258
|
+
updates.push({
|
|
259
|
+
drop: false,
|
|
260
|
+
start: segmentStart,
|
|
261
|
+
length: segmentEnd - segmentStart
|
|
262
|
+
})
|
|
255
263
|
}
|
|
256
264
|
|
|
257
265
|
for (let i = 0; i < length * 2; i++) {
|
|
@@ -295,6 +303,10 @@ module.exports = class Core {
|
|
|
295
303
|
this.header.userData = src.header.userData.slice(0)
|
|
296
304
|
this.header.hints.contiguousLength = Math.min(src.header.hints.contiguousLength, this.header.tree.length)
|
|
297
305
|
|
|
306
|
+
for (const bitfield of updates) {
|
|
307
|
+
this.onupdate(0b0001, bitfield, null, null)
|
|
308
|
+
}
|
|
309
|
+
|
|
298
310
|
await this._flushOplog()
|
|
299
311
|
} finally {
|
|
300
312
|
src._mutex.unlock()
|
package/lib/remote-bitfield.js
CHANGED
|
@@ -149,6 +149,7 @@ module.exports = class RemoteBitfield {
|
|
|
149
149
|
constructor () {
|
|
150
150
|
this._pages = new BigSparseArray()
|
|
151
151
|
this._segments = new BigSparseArray()
|
|
152
|
+
this._maxSegments = 0
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
getBitfield (index) {
|
|
@@ -177,6 +178,7 @@ module.exports = class RemoteBitfield {
|
|
|
177
178
|
if (!p && val) {
|
|
178
179
|
const k = Math.floor(i / PAGES_PER_SEGMENT)
|
|
179
180
|
const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
|
|
181
|
+
if (this._maxSegments <= k) this._maxSegments = k + 1
|
|
180
182
|
|
|
181
183
|
p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
|
|
182
184
|
}
|
|
@@ -194,6 +196,7 @@ module.exports = class RemoteBitfield {
|
|
|
194
196
|
if (!p && val) {
|
|
195
197
|
const k = Math.floor(i / PAGES_PER_SEGMENT)
|
|
196
198
|
const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
|
|
199
|
+
if (this._maxSegments <= k) this._maxSegments = k + 1
|
|
197
200
|
|
|
198
201
|
p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
|
|
199
202
|
}
|
|
@@ -213,7 +216,7 @@ module.exports = class RemoteBitfield {
|
|
|
213
216
|
let j = position & (BITS_PER_SEGMENT - 1)
|
|
214
217
|
let i = (position - j) / BITS_PER_SEGMENT
|
|
215
218
|
|
|
216
|
-
while (i < this.
|
|
219
|
+
while (i < this._maxSegments) {
|
|
217
220
|
const s = this._segments.get(i)
|
|
218
221
|
|
|
219
222
|
let index = -1
|
|
@@ -281,6 +284,7 @@ module.exports = class RemoteBitfield {
|
|
|
281
284
|
if (!p) {
|
|
282
285
|
const k = Math.floor(i / PAGES_PER_SEGMENT)
|
|
283
286
|
const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
|
|
287
|
+
if (this._maxSegments <= k) this._maxSegments = k + 1
|
|
284
288
|
|
|
285
289
|
p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
|
|
286
290
|
}
|
|
@@ -314,6 +318,7 @@ module.exports = class RemoteBitfield {
|
|
|
314
318
|
if (!p) {
|
|
315
319
|
const k = Math.floor(i / PAGES_PER_SEGMENT)
|
|
316
320
|
const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
|
|
321
|
+
if (this._maxSegments <= k) this._maxSegments = k + 1
|
|
317
322
|
|
|
318
323
|
p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
|
|
319
324
|
}
|
package/lib/streams.js
CHANGED
|
@@ -105,7 +105,7 @@ class ByteStream extends Readable {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
this._predownload(this._index + 1)
|
|
108
|
-
data = await this._core.get(this._index
|
|
108
|
+
data = await this._core.get(this._index++, { valueEncoding: 'binary' })
|
|
109
109
|
|
|
110
110
|
if (relativeOffset > 0) data = data.subarray(relativeOffset)
|
|
111
111
|
|