hypercore 11.8.3 → 11.9.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/session-state.js +5 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -920,7 +920,7 @@ class Hypercore extends EventEmitter {
|
|
|
920
920
|
const isDefault = this.state === this.core.state
|
|
921
921
|
const defaultKeyPair = this.state.name === null ? this.keyPair : null
|
|
922
922
|
|
|
923
|
-
const { keyPair = defaultKeyPair, signature = null } = opts
|
|
923
|
+
const { keyPair = defaultKeyPair, signature = null, maxLength } = opts
|
|
924
924
|
const writable = !isDefault || !!signature || !!(keyPair && keyPair.secretKey) || opts.writable === true
|
|
925
925
|
|
|
926
926
|
if (this._readonly || writable === false) throw SESSION_NOT_WRITABLE()
|
|
@@ -942,7 +942,7 @@ class Hypercore extends EventEmitter {
|
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
|
|
945
|
-
return this.state.append(buffers, { keyPair, signature, preappend })
|
|
945
|
+
return this.state.append(buffers, { keyPair, signature, preappend, maxLength })
|
|
946
946
|
}
|
|
947
947
|
|
|
948
948
|
async signable (length = -1, fork = -1) {
|
package/lib/session-state.js
CHANGED
|
@@ -503,12 +503,16 @@ module.exports = class SessionState {
|
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
async append (values, { signature, keyPair, preappend } = {}) {
|
|
506
|
+
async append (values, { signature, keyPair, preappend, maxLength = -1 } = {}) {
|
|
507
507
|
if (!keyPair && this.isDefault()) keyPair = this.core.header.keyPair
|
|
508
508
|
|
|
509
509
|
await this.mutex.lock()
|
|
510
510
|
|
|
511
511
|
try {
|
|
512
|
+
if (maxLength >= 0 && (this.length + values.length) > maxLength) {
|
|
513
|
+
return { length: this.length, byteLength: this.byteLength }
|
|
514
|
+
}
|
|
515
|
+
|
|
512
516
|
const tx = this.createWriteBatch()
|
|
513
517
|
|
|
514
518
|
// upsert compat manifest
|