hypercore 11.0.7 → 11.0.8

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/bitfield.js CHANGED
@@ -330,14 +330,15 @@ module.exports = class Bitfield {
330
330
  p = this._pages.set(i, new BitfieldPage(i, s))
331
331
  }
332
332
 
333
- const last = Math.min(end, BITS_PER_PAGE)
333
+ const offset = p.index * BITS_PER_PAGE
334
+ const last = Math.min(end - offset, BITS_PER_PAGE)
334
335
  const range = last - j
335
336
 
336
337
  if (p) p.setRange(j, last, val)
337
338
 
338
339
  j = 0
339
340
  i++
340
- end -= range
341
+ start += range
341
342
  }
342
343
  }
343
344
 
@@ -639,12 +639,21 @@ module.exports = class SessionState {
639
639
  const firstPage = getBitfieldPage(treeLength)
640
640
  const lastPage = getBitfieldPage(totalLength)
641
641
 
642
+ const srx = this.storage.read()
643
+ const bitfieldPagePromise = srx.getBitfieldPage(firstPage)
644
+ srx.tryFlush()
645
+
646
+ const bitfieldPage = await bitfieldPagePromise
647
+
642
648
  let index = treeLength
643
649
 
644
650
  for (let i = firstPage; i <= lastPage; i++) {
645
651
  const page = b4a.alloc(Bitfield.BYTES_PER_PAGE)
646
652
  tx.putBitfieldPage(i, page)
647
653
 
654
+ // copy existing bits in
655
+ if (i === firstPage && bitfieldPage) page.set(bitfieldPage)
656
+
648
657
  if (index < length) {
649
658
  index = fillBitfieldPage(page, index, length, i, true)
650
659
  if (index < length) continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.0.7",
3
+ "version": "11.0.8",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {