You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds an example to the readme of how to use a custom hasher with the helia data importing utils.
Closes: #640
---------
Co-authored-by: Alex Potsides <[email protected]>
A [hasher](https://github.com/multiformats/js-multiformats?tab=readme-ov-file#multihash-hashers) is used to determine the immutable address of the content (aka the [**CID**](https://github.com/multiformats/cid?tab=readme-ov-file#what-is-it)) being imported into helia. The default hasher used by the methods above is [sha2-256 multihash](https://github.com/multiformats/js-multiformats?tab=readme-ov-file#multihash-hashers-1), but others can be provided with [AddOptions](https://helia.io/interfaces/_helia_dag_cbor.AddOptions.html). This is useful for applications that require hashers with specific properties; so in most cases keeping the default is recommended.
114
+
115
+
> **Changing the hasher will cause a different CID to be returned for the same content! In other words: the same content imported with different hashers is treated like unique content with a unique address.**
116
+
117
+
```js
118
+
import { createHelia } from'helia'
119
+
import { dagCbor } from'@helia/dag-cbor'
120
+
import { sha512 } from'multiformats/hashes/sha2'
121
+
122
+
consthelia=awaitcreateHelia()
123
+
constd=dagCbor(helia)
124
+
125
+
constobject1= { hello:'world' }
126
+
127
+
constcidWithSHA256=awaitd.add(object1)
128
+
constcidWithSHA512=awaitd.add(object1, {
129
+
hasher: sha512
130
+
})
131
+
132
+
/** The same objects with different CIDs are treated as different objects */
0 commit comments