hypercore 10.0.0-alpha.47 → 10.0.0-alpha.48
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 +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,8 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
|
|
|
66
66
|
valueEncoding: 'json' | 'utf-8' | 'binary', // defaults to binary
|
|
67
67
|
encodeBatch: batch => { ... }, // optionally apply an encoding to complete batches
|
|
68
68
|
keyPair: kp, // optionally pass the public key and secret key as a key pair
|
|
69
|
-
encryptionKey: k // optionally pass an encryption key to enable block encryption
|
|
69
|
+
encryptionKey: k, // optionally pass an encryption key to enable block encryption
|
|
70
|
+
onwait: () => {} // hook that is called if gets are waiting for download
|
|
70
71
|
}
|
|
71
72
|
```
|
|
72
73
|
|
package/index.js
CHANGED
|
@@ -70,6 +70,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
70
70
|
this.sessions = opts._sessions || [this]
|
|
71
71
|
this.auth = opts.auth || null
|
|
72
72
|
this.autoClose = !!opts.autoClose
|
|
73
|
+
this.onwait = opts.onwait || null
|
|
73
74
|
|
|
74
75
|
this.closing = null
|
|
75
76
|
this.opening = this._openSession(key, storage, opts)
|
|
@@ -589,14 +590,17 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
589
590
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
590
591
|
const req = this.replicator.addUpgrade(activeRequests)
|
|
591
592
|
|
|
592
|
-
|
|
593
|
+
let upgraded = await req.promise
|
|
593
594
|
|
|
594
595
|
if (!this.sparse) {
|
|
595
596
|
// Download all available blocks in non-sparse mode
|
|
596
597
|
const start = this.length
|
|
597
598
|
const end = this.core.tree.length
|
|
599
|
+
const contig = this.contiguousLength
|
|
598
600
|
|
|
599
601
|
await this.download({ start, end, ifAvailable: true }).downloaded()
|
|
602
|
+
|
|
603
|
+
if (!upgraded) upgraded = this.contiguousLength !== contig
|
|
600
604
|
}
|
|
601
605
|
|
|
602
606
|
if (!upgraded) return false
|
|
@@ -659,6 +663,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
659
663
|
} else {
|
|
660
664
|
if (opts && opts.wait === false) return null
|
|
661
665
|
if (opts && opts.onwait) opts.onwait(index)
|
|
666
|
+
else if (this.onwait) this.onwait(index)
|
|
662
667
|
|
|
663
668
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
664
669
|
|