hypercore 10.7.0 → 10.8.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/README.md +9 -2
- package/index.js +20 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ console.log('core was updated?', updated, 'length is', core.length)
|
|
|
145
145
|
|
|
146
146
|
Use `core.findingPeers()` or `{ wait: true }` to make `await core.update()` blocking.
|
|
147
147
|
|
|
148
|
-
#### `const [index, relativeOffset] = await core.seek(byteOffset)`
|
|
148
|
+
#### `const [index, relativeOffset] = await core.seek(byteOffset, [options])`
|
|
149
149
|
|
|
150
150
|
Seek to a byte offset.
|
|
151
151
|
|
|
@@ -160,6 +160,13 @@ const second = await core.seek(3) // returns [1, 0]
|
|
|
160
160
|
const third = await core.seek(5) // returns [2, 1]
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
+
``` js
|
|
164
|
+
{
|
|
165
|
+
wait: true, // wait for data to be downloaded
|
|
166
|
+
timeout: 0 // wait at max some milliseconds (0 means no timeout)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
163
170
|
#### `const stream = core.createReadStream([options])`
|
|
164
171
|
|
|
165
172
|
Make a read stream to read a range of data out at once.
|
|
@@ -292,7 +299,7 @@ Fully close this core.
|
|
|
292
299
|
|
|
293
300
|
#### `core.on('close')`
|
|
294
301
|
|
|
295
|
-
Emitted when
|
|
302
|
+
Emitted when the core has been fully closed.
|
|
296
303
|
|
|
297
304
|
#### `await core.ready()`
|
|
298
305
|
|
package/index.js
CHANGED
|
@@ -472,6 +472,10 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
472
472
|
return this.core.tree.length
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
get indexedLength () {
|
|
476
|
+
return this.length
|
|
477
|
+
}
|
|
478
|
+
|
|
475
479
|
/**
|
|
476
480
|
* Deprecated. Use `const { byteLength } = await core.info()`.
|
|
477
481
|
*/
|
|
@@ -649,7 +653,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
649
653
|
return this._updateSnapshot()
|
|
650
654
|
}
|
|
651
655
|
|
|
652
|
-
const remoteWait =
|
|
656
|
+
const remoteWait = this._shouldWait(opts, this.replicator.findingPeers > 0)
|
|
653
657
|
|
|
654
658
|
let upgraded = false
|
|
655
659
|
|
|
@@ -679,9 +683,14 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
679
683
|
|
|
680
684
|
if (this.closing !== null) throw SESSION_CLOSED()
|
|
681
685
|
|
|
686
|
+
if (!this._shouldWait(opts, this.wait)) return null
|
|
687
|
+
|
|
682
688
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
683
689
|
const req = this.replicator.addSeek(activeRequests, s)
|
|
684
690
|
|
|
691
|
+
const timeout = opts && opts.timeout !== undefined ? opts.timeout : this.timeout
|
|
692
|
+
if (timeout) req.context.setTimeout(req, timeout)
|
|
693
|
+
|
|
685
694
|
return req.promise
|
|
686
695
|
}
|
|
687
696
|
|
|
@@ -741,8 +750,8 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
741
750
|
|
|
742
751
|
if (this.cache) this.cache.set(index, block)
|
|
743
752
|
} else {
|
|
744
|
-
if (opts
|
|
745
|
-
|
|
753
|
+
if (!this._shouldWait(opts, this.wait)) return null
|
|
754
|
+
|
|
746
755
|
if (opts && opts.onwait) opts.onwait(index, this)
|
|
747
756
|
if (this.onwait) this.onwait(index, this)
|
|
748
757
|
|
|
@@ -769,6 +778,14 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
769
778
|
return block
|
|
770
779
|
}
|
|
771
780
|
|
|
781
|
+
_shouldWait (opts, defaultValue) {
|
|
782
|
+
if (opts) {
|
|
783
|
+
if (opts.wait === false) return false
|
|
784
|
+
if (opts.wait === true) return true
|
|
785
|
+
}
|
|
786
|
+
return defaultValue
|
|
787
|
+
}
|
|
788
|
+
|
|
772
789
|
createReadStream (opts) {
|
|
773
790
|
return new ReadStream(this, opts)
|
|
774
791
|
}
|