Skip to content

Commit b293b38

Browse files
committed
fix: clean up and simplify example
1 parent d12595e commit b293b38

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
`MultihashHashers`s are exported from this library, they produce `MultihashDigest`s. Details about these can be found in the [multiformats multihash interface definitions](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts).
66

77
```js
8-
import CID from 'multiformats/cid'
9-
import * as dagCbor from '@ipld/dag-cbor'
10-
import { blake2b256 } from '@multiformats/blake2/blake2b'
8+
import * as Block from 'multiformats/block'
9+
import * as codec from '@ipld/dag-cbor'
10+
import { blake2b256 as hasher } from '@multiformats/blake2/blake2b'
1111

1212
async function run () {
13-
const bytes = dagCbor.encode({ hello: 'world' })
14-
const hash = await blake2b256.digest(bytesMultihashHasher)
15-
const cid = CID.create(1, dagCbor.code, hash)
16-
console.log(cid)
17-
//> CID(bafy2bzacedtxqx7k666ugf5mmagr2fxmbpfncbcji5jfg5uduausgb62y3av4)
13+
const value = { hello: 'world' }
14+
const block = await Block.encode({ value, hasher, codec })
15+
console.log(block.cid)
16+
// -> CID(bafy2bzacedtxqx7k666ugf5mmagr2fxmbpfncbcji5jfg5uduausgb62y3av4)
1817
}
1918

2019
run().catch(console.error)

example.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { CID } from 'multiformats/cid'
2-
import * as dagCbor from '@ipld/dag-cbor'
3-
import { blake2b256 } from '@multiformats/blake2/blake2b'
1+
import * as Block from 'multiformats/block'
2+
import * as codec from '@ipld/dag-cbor'
3+
import { blake2b256 as hasher } from '@multiformats/blake2/blake2b'
44

55
async function run () {
6-
const bytes = dagCbor.encode({ hello: 'world' })
7-
8-
const hash = await blake2b256.digest(bytes)
9-
const cid = CID.create(1, dagCbor.code, hash)
10-
console.log(cid)
6+
const value = { hello: 'world' }
7+
const block = await Block.encode({ value, hasher, codec })
8+
console.log(block.cid)
119
// -> CID(bafy2bzacedtxqx7k666ugf5mmagr2fxmbpfncbcji5jfg5uduausgb62y3av4)
1210
}
1311

0 commit comments

Comments
 (0)