hypercore 11.10.1 → 11.11.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 CHANGED
@@ -61,15 +61,24 @@ Alternatively you can pass a [Hypercore Storage](https://github.com/holepunchto/
61
61
  ongc: (session) => { ... }, // A callback called when the session is garbage collected
62
62
  notDownloadingLinger: 20000, // How many milliseconds to wait after downloading finishes keeping the connection open. Defaults to a random number between 20-40s
63
63
  allowFork: true, // Enables updating core when it forks
64
+ userData: { foo: 'bar' }, // An object to assign to the local User Uata storage
64
65
  }
65
66
  ```
66
67
 
67
- You can also set valueEncoding to any [compact-encoding](https://github.com/compact-encoding) instance.
68
+ You can also set `valueEncoding` to any [compact-encoding](https://github.com/compact-encoding) instance.
68
69
 
69
- valueEncodings will be applied to individual blocks, even if you append batches. If you want to control encoding at the batch-level, you can use the `encodeBatch` option, which is a function that takes a batch and returns a binary-encoded batch. If you provide a custom valueEncoding, it will not be applied prior to `encodeBatch`.
70
+ `valueEncoding`s will be applied to individual blocks, even if you append batches. If you want to control encoding at the batch-level, you can use the `encodeBatch` option, which is a function that takes a batch and returns a binary-encoded batch. If you provide a custom `valueEncoding`, it will not be applied prior to `encodeBatch`.
70
71
 
71
72
  The user may provide a custom encryption module as `opts.encryption`, which should satisfy the [HypercoreEncryption](https://github.com/holepunchto/hypercore-encryption) interface.
72
73
 
74
+ ##### User Data
75
+
76
+ User Data is a key-value store that is persisted locally and is not replicated with the Hypercore. This is useful as a quick store for data only used by the current peer. For example, `autobase` uses User Data to store information such as encryption keys and connections between a peer's local writer and the Autobase's bootstrap core.
77
+
78
+ Keys are always strings and values can be strings or buffers.
79
+
80
+ See [`core.setUserData(key, value)`](#await-coresetuserdatakey-value) and [`core.getUserData(key)`](#const-value--await-coregetuserdatakey) for updating User Data.
81
+
73
82
  #### `const { length, byteLength } = await core.append(block)`
74
83
 
75
84
  Append a block of data (or an array of blocks) to the core.
@@ -455,6 +464,18 @@ Populated after `ready` has been emitted. Will be `0` before the event.
455
464
 
456
465
  How much padding is applied to each block of this core? Will be `0` unless block encryption is enabled.
457
466
 
467
+ #### `await core.setUserData(key, value)`
468
+
469
+ Set a key in the User Data key-value store.
470
+
471
+ `key` is a string and `value` can be a string or buffer.
472
+
473
+ #### `const value = await core.getUserData(key)`
474
+
475
+ Return the value for a key in the User Data key-value store.
476
+
477
+ `key` is a string.
478
+
458
479
  #### `const stream = core.replicate(isInitiatorOrReplicationStream)`
459
480
 
460
481
  Create a replication stream. You should pipe this to another Hypercore instance.
@@ -1091,8 +1091,9 @@ function nodesToRoot (index, nodes, head) {
1091
1091
  const ite = flat.iterator(index)
1092
1092
 
1093
1093
  for (let i = 0; i < nodes; i++) {
1094
+ const index = ite.index
1094
1095
  ite.parent()
1095
- if (ite.contains(head)) throw BAD_ARGUMENT('Nodes is out of bounds')
1096
+ if (ite.contains(head)) return index
1096
1097
  }
1097
1098
 
1098
1099
  return ite.index
package/lib/streams.js CHANGED
@@ -9,6 +9,8 @@ class ReadStream extends Readable {
9
9
  this.end = typeof opts.end === 'number' ? opts.end : -1
10
10
  this.snapshot = !opts.live && opts.snapshot !== false
11
11
  this.live = this.end === -1 ? !!opts.live : false
12
+ this.wait = typeof opts.wait === 'boolean' ? opts.wait : this.core.wait
13
+ this.timeout = opts.timeout || core.timeout
12
14
  }
13
15
 
14
16
  _open (cb) {
@@ -32,7 +34,7 @@ class ReadStream extends Readable {
32
34
  return
33
35
  }
34
36
 
35
- this.push(await this.core.get(this.start++))
37
+ this.push(await this.core.get(this.start++, { wait: this.wait, timeout: this.timeout }))
36
38
  }
37
39
  }
38
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.10.1",
3
+ "version": "11.11.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {