hypercore 10.11.0 → 10.12.0
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/README.md +2 -1
- package/index.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,8 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
|
|
|
72
72
|
encodeBatch: batch => { ... }, // optionally apply an encoding to complete batches
|
|
73
73
|
keyPair: kp, // optionally pass the public key and secret key as a key pair
|
|
74
74
|
encryptionKey: k, // optionally pass an encryption key to enable block encryption
|
|
75
|
-
onwait: () => {} // hook that is called if gets are waiting for download
|
|
75
|
+
onwait: () => {}, // hook that is called if gets are waiting for download
|
|
76
|
+
writable: true // disable appends and truncates
|
|
76
77
|
}
|
|
77
78
|
```
|
|
78
79
|
|
package/index.js
CHANGED
|
@@ -74,6 +74,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
74
74
|
this.onwait = opts.onwait || null
|
|
75
75
|
this.wait = opts.wait !== false
|
|
76
76
|
this.timeout = opts.timeout || 0
|
|
77
|
+
this._readonly = opts.writable === false
|
|
77
78
|
|
|
78
79
|
this.closing = null
|
|
79
80
|
this.opening = this._openSession(key, storage, opts)
|
|
@@ -201,6 +202,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
201
202
|
|
|
202
203
|
const sparse = opts.sparse === false ? false : this.sparse
|
|
203
204
|
const wait = opts.wait === false ? false : this.wait
|
|
205
|
+
const writable = opts.writable === false ? false : !this._readonly
|
|
204
206
|
const onwait = opts.onwait === undefined ? this.onwait : opts.onwait
|
|
205
207
|
const timeout = opts.timeout === undefined ? this.timeout : opts.timeout
|
|
206
208
|
const Clz = opts.class || Hypercore
|
|
@@ -210,6 +212,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
210
212
|
wait,
|
|
211
213
|
onwait,
|
|
212
214
|
timeout,
|
|
215
|
+
writable,
|
|
213
216
|
_opening: this.opening,
|
|
214
217
|
_sessions: this.sessions
|
|
215
218
|
})
|
|
@@ -237,7 +240,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
237
240
|
this.core = o.core
|
|
238
241
|
this.replicator = o.replicator
|
|
239
242
|
this.encryption = o.encryption
|
|
240
|
-
this.writable = !!(this.auth && this.auth.sign)
|
|
243
|
+
this.writable = !this._readonly && !!(this.auth && this.auth.sign)
|
|
241
244
|
this.autoClose = o.autoClose
|
|
242
245
|
|
|
243
246
|
if (this.snapshotted && this.core && !this._snapshot) this._updateSnapshot()
|
|
@@ -295,7 +298,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
if (!this.auth) this.auth = this.core.defaultAuth
|
|
298
|
-
this.writable = !!this.auth.sign
|
|
301
|
+
this.writable = !this._readonly && !!this.auth.sign
|
|
299
302
|
|
|
300
303
|
if (opts.valueEncoding) {
|
|
301
304
|
this.valueEncoding = c.from(opts.valueEncoding)
|