Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit d1ee91b

Browse files
Alan Shawvmx
Alan Shaw
authored andcommitted
docs: update usage docs for base32 encoded CIDv1
1 parent 6c5a137 commit d1ee91b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ You can create an instance from a CID string or CID Buffer
5959
```js
6060
const CID = require('cids')
6161

62-
const cid = new CID('zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY')
62+
const cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')
6363

6464
cid.version // 1
6565
cid.codec // 'dag-pb'
66-
cid.multibaseName // 'base58btc'
66+
cid.multibaseName // 'base32'
6767
cid.toString()
68-
// 'zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY'
68+
// 'bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu'
6969
```
7070

7171
or by specifying the [cid version](https://github.com/multiformats/cid#versions), [multicodec name](https://github.com/multiformats/multicodec/blob/master/table.csv) and [multihash](https://github.com/multiformats/multihash):
@@ -74,28 +74,28 @@ or by specifying the [cid version](https://github.com/multiformats/cid#versions)
7474
const CID = require('cids')
7575
const multihashing = require('multihashing-async')
7676

77-
multihashing(Buffer.from('OMG!'), 'sha2-256', (err, hash) => {
78-
const cid = new CID(1, 'dag-pb', hash)
79-
console.log(cid.toString())
80-
// zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY
81-
})
77+
const hash = await multihashing(Buffer.from('OMG!'), 'sha2-256')
78+
const cid = new CID(1, 'dag-pb', hash)
79+
console.log(cid.toString())
80+
// bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu
8281
```
8382

84-
The string form of CIDs currently defaults to `base58btc` flavour. (This is [soon to change to `base32`](https://github.com/ipfs/ipfs/issues/337). When creating a new instance you can optionally specify the default multibase to use when calling `toBaseEncodedString()` or `toString()`
83+
The string form of v1 CIDs defaults to `base32` encoding (v0 CIDs are always `base58btc` encoded). When creating a new instance you can optionally specify the default multibase to use when calling `toBaseEncodedString()` or `toString()`
8584

8685

8786
```js
88-
const cid = new CID(1, 'raw', hash, 'base32')
87+
const cid = new CID(1, 'raw', hash, 'base64')
8988
console.log(cid.toString())
90-
// bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu
89+
// mAXASIN69ets85WVE0ipva5M5b2mAqAZ8LME08PeAG2MxCSuV
9190
```
9291

9392
If you construct an instance from a valid CID string, the base you provided will be preserved as the default.
9493

9594
```js
96-
const cid = new CID('bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy')
95+
// e.g. a base64url encoded CID
96+
const cid = new CID('uAXASIHJSUj5lkfuP5VPWf_VahvhARLRqPkF24QxY-lKaSqvV')
9797
cid.toString()
98-
// bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy
98+
// uAXASIHJSUj5lkfuP5VPWf_VahvhARLRqPkF24QxY-lKaSqvV
9999
```
100100

101101

0 commit comments

Comments
 (0)