hypercore-storage 1.6.0 → 1.6.1

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