hypercore 10.14.0 → 10.15.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.
- package/index.js +2 -2
- package/lib/core.js +3 -3
- package/lib/oplog.js +3 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -633,9 +633,9 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
635
|
|
|
636
|
-
async setUserData (key, value) {
|
|
636
|
+
async setUserData (key, value, { flush = false } = {}) {
|
|
637
637
|
if (this.opened === false) await this.opening
|
|
638
|
-
return this.core.userData(key, value)
|
|
638
|
+
return this.core.userData(key, value, flush)
|
|
639
639
|
}
|
|
640
640
|
|
|
641
641
|
async getUserData (key) {
|
package/lib/core.js
CHANGED
|
@@ -73,7 +73,7 @@ module.exports = class Core {
|
|
|
73
73
|
const oplog = new Oplog(oplogFile, {
|
|
74
74
|
headerEncoding: m.oplog.header,
|
|
75
75
|
entryEncoding: m.oplog.entry,
|
|
76
|
-
|
|
76
|
+
readonly: opts.readonly
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
let { header, entries } = await oplog.open()
|
|
@@ -192,7 +192,7 @@ module.exports = class Core {
|
|
|
192
192
|
await this.blocks.put(index, value, byteOffset)
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
async userData (key, value) {
|
|
195
|
+
async userData (key, value, flush) {
|
|
196
196
|
// TODO: each oplog append can set user data, so we should have a way
|
|
197
197
|
// to just hitch a ride on one of the other ongoing appends?
|
|
198
198
|
await this._mutex.lock()
|
|
@@ -220,7 +220,7 @@ module.exports = class Core {
|
|
|
220
220
|
|
|
221
221
|
updateUserData(this.header.userData, key, value)
|
|
222
222
|
|
|
223
|
-
if (this._shouldFlush()) await this._flushOplog()
|
|
223
|
+
if (this._shouldFlush() || flush) await this._flushOplog()
|
|
224
224
|
} finally {
|
|
225
225
|
this._mutex.unlock()
|
|
226
226
|
}
|
package/lib/oplog.js
CHANGED
|
@@ -4,11 +4,11 @@ const { crc32 } = require('crc-universal')
|
|
|
4
4
|
const { OPLOG_CORRUPT } = require('./errors')
|
|
5
5
|
|
|
6
6
|
module.exports = class Oplog {
|
|
7
|
-
constructor (storage, { pageSize = 4096, headerEncoding = cenc.raw, entryEncoding = cenc.raw,
|
|
7
|
+
constructor (storage, { pageSize = 4096, headerEncoding = cenc.raw, entryEncoding = cenc.raw, readonly = false } = {}) {
|
|
8
8
|
this.storage = storage
|
|
9
9
|
this.headerEncoding = headerEncoding
|
|
10
10
|
this.entryEncoding = entryEncoding
|
|
11
|
-
this.
|
|
11
|
+
this.readonly = readonly
|
|
12
12
|
this.flushed = false
|
|
13
13
|
this.byteLength = 0
|
|
14
14
|
this.length = 0
|
|
@@ -102,8 +102,6 @@ module.exports = class Oplog {
|
|
|
102
102
|
|
|
103
103
|
result.header = header ? h2.message : h1.message
|
|
104
104
|
|
|
105
|
-
if (this.headerOnly) return result
|
|
106
|
-
|
|
107
105
|
while (true) {
|
|
108
106
|
const entry = this._decodeEntry(state, this.entryEncoding)
|
|
109
107
|
if (!entry) break
|
|
@@ -125,6 +123,7 @@ module.exports = class Oplog {
|
|
|
125
123
|
if (size === buffer.byteLength) return result
|
|
126
124
|
|
|
127
125
|
await new Promise((resolve, reject) => {
|
|
126
|
+
if (this.readonly) return resolve()
|
|
128
127
|
this.storage.truncate(size, err => {
|
|
129
128
|
if (err) return reject(err)
|
|
130
129
|
resolve()
|