hypercore 11.35.2 → 11.35.4
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 +4 -0
- package/lib/mark-bitfield.js +4 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -376,6 +376,10 @@ class Hypercore extends EventEmitter {
|
|
|
376
376
|
async _openSession(opts) {
|
|
377
377
|
if (this.core.opened === false) await this.core.ready()
|
|
378
378
|
|
|
379
|
+
if (opts.group && !this.core.header.group) {
|
|
380
|
+
await this.core.setGroup(opts.group)
|
|
381
|
+
}
|
|
382
|
+
|
|
379
383
|
if (this.keyPair === null) this.keyPair = opts.keyPair || this.core.header.keyPair
|
|
380
384
|
|
|
381
385
|
const parent = opts.parent || null
|
package/lib/mark-bitfield.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const BigSparseArray = require('big-sparse-array')
|
|
2
2
|
const { Transform } = require('streamx')
|
|
3
3
|
const quickbit = require('./compat').quickbit
|
|
4
|
+
const Mutex = require('./mutex')
|
|
4
5
|
const b4a = require('b4a')
|
|
5
6
|
|
|
6
7
|
const BITS_PER_PAGE = 32768
|
|
@@ -34,6 +35,7 @@ module.exports = class MarkBitfield {
|
|
|
34
35
|
|
|
35
36
|
constructor(storage) {
|
|
36
37
|
this.storage = storage
|
|
38
|
+
this.mutex = new Mutex()
|
|
37
39
|
this._pages = new BigSparseArray()
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -68,9 +70,11 @@ module.exports = class MarkBitfield {
|
|
|
68
70
|
if (p) {
|
|
69
71
|
await p.loaded
|
|
70
72
|
p.set(j, val)
|
|
73
|
+
await this.mutex.lock()
|
|
71
74
|
const tx = this.storage.write()
|
|
72
75
|
tx.putMark(i, p.bitfield)
|
|
73
76
|
await tx.flush()
|
|
77
|
+
this.mutex.unlock()
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|