hypercore 11.11.0 → 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 +23 -2
- package/lib/merkle-tree.js +2 -1
- package/package.json +1 -1
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
|
-
|
|
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.
|
package/lib/merkle-tree.js
CHANGED
|
@@ -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))
|
|
1096
|
+
if (ite.contains(head)) return index
|
|
1096
1097
|
}
|
|
1097
1098
|
|
|
1098
1099
|
return ite.index
|