hypercore-storage 1.6.0 → 1.6.2
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/migrations/0/index.js +9 -9
- package/package.json +1 -1
package/migrations/0/index.js
CHANGED
|
@@ -236,6 +236,7 @@ class BlockSlicer {
|
|
|
236
236
|
|
|
237
237
|
async take (offset, size) {
|
|
238
238
|
let buffer = null
|
|
239
|
+
if (offset < this.offset) throw new Error('overread')
|
|
239
240
|
|
|
240
241
|
while (true) {
|
|
241
242
|
let data = null
|
|
@@ -254,7 +255,7 @@ class BlockSlicer {
|
|
|
254
255
|
|
|
255
256
|
let chunk = null
|
|
256
257
|
|
|
257
|
-
if (this.offset === offset) {
|
|
258
|
+
if (this.offset === offset || buffer) {
|
|
258
259
|
chunk = data
|
|
259
260
|
} else if (this.offset + data.byteLength > offset) {
|
|
260
261
|
chunk = data.subarray(offset - this.offset)
|
|
@@ -266,11 +267,11 @@ class BlockSlicer {
|
|
|
266
267
|
if (buffer) buffer = b4a.concat([buffer, chunk])
|
|
267
268
|
else buffer = chunk
|
|
268
269
|
|
|
269
|
-
if (
|
|
270
|
+
if (buffer.byteLength < size) continue
|
|
270
271
|
|
|
271
|
-
const result =
|
|
272
|
-
this.overflow = size ===
|
|
273
|
-
this.offset -= this.overflow ? this.overflow.byteLength : 0
|
|
272
|
+
const result = buffer.subarray(0, size)
|
|
273
|
+
this.overflow = size === buffer.byteLength ? null : buffer.subarray(result.byteLength)
|
|
274
|
+
this.offset -= (this.overflow ? this.overflow.byteLength : 0)
|
|
274
275
|
return result
|
|
275
276
|
}
|
|
276
277
|
}
|
|
@@ -517,9 +518,8 @@ async function core (core, { version, dryRun = true, gc = true }) {
|
|
|
517
518
|
const index = batch[i]
|
|
518
519
|
const [offset, size] = r[i]
|
|
519
520
|
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
tx.putBlock(index, block)
|
|
521
|
+
const blk = await blocks.take(offset, size)
|
|
522
|
+
tx.putBlock(index, blk)
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
batch = []
|
|
@@ -550,7 +550,7 @@ async function commitCoreMigration (auth, core, version) {
|
|
|
550
550
|
|
|
551
551
|
async function getBlockFromFile (file, core, index, roots, cache) {
|
|
552
552
|
const rx = core.read()
|
|
553
|
-
const promise = getByteRangeFromStorage(rx, index, roots, cache)
|
|
553
|
+
const promise = getByteRangeFromStorage(rx, 2 * index, roots, cache)
|
|
554
554
|
rx.tryFlush()
|
|
555
555
|
const [offset, size] = await promise
|
|
556
556
|
|