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
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-[Adding additional BlockCodecs, Multihashes and Multibases](#adding-additional-blockcodecs-multihashes-and-multibases)
8
10
-[Next steps](#next-steps)
9
11
10
12
## Overview
11
13
12
-
The IPFS repo contains a blockstore that holds [Blocks](https://github.com/ipld/js-ipld-block). These blocks can be thought of as a [CID][] and associated byte array.
14
+
The IPFS repo contains a blockstore that holds the data that makes up the files on the IPFS network. These blocks can be thought of as a [CID][] and associated byte array.
13
15
14
-
The [CID][] contains a `codec` property that lets us know how to interpret the byte array associated with it.
16
+
The [CID][] contains a `code` property that lets us know how to interpret the byte array associated with it.
15
17
16
-
In order to perform that interpretation, an [IPLD Format][] must be loaded that corresponds to the `codec` property of the [CID][].
18
+
In order to perform that interpretation, a [BlockCodec][] must be loaded that corresponds to the `code` property of the [CID][].
17
19
18
-
## Bundled Codecs
20
+
Similarly implementations of [Multihash][]es or [Multibase][]s must be available to be used.
19
21
20
-
js-IPFS ships with three bundled codecs, the ones that are required to create and interpret [UnixFS][] structures.
22
+
## Bundled BlockCodecs
23
+
24
+
js-IPFS ships with four bundled codecs, the ones that are required to create and interpret [UnixFS][] structures.
21
25
22
26
These are:
23
27
24
-
1.[ipld-dag-pb](https://github.com/ipld/js-ipld-dag-pb) - used for file and directory structures
25
-
2.[ipld-raw](https://github.com/ipld/js-ipld-raw) - used for file data where imported with `raw-leaves=true`
26
-
3.[ipld-dag-cbor](https://github.com/ipld/js-ipld-dag-cbor) - used for general storage of JavaScript Objects
28
+
1.[@ipld/dag-pb](https://github.com/ipld/js-dag-pb) - used for file and directory structures
29
+
2.[raw](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/raw.js) - used for file data where imported with `--raw-leaves=true`
30
+
3.[@ipld/dag-cbor](https://github.com/ipld/js-dag-cbor) - used for storage of JavaScript Objects with [CID] links to other blocks
31
+
4.[json](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/json.js) - used for storage of plain JavaScript Objects
32
+
33
+
## Bundled Multihashes
34
+
35
+
js-IPFS ships with all multihashes [exported by js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes), including `sha2-256` and others.
36
+
37
+
Additional hashers can be configured using the `hashers` config property.
38
+
39
+
## Bundled Multibases
40
+
41
+
js-IPFS ships with all multibases [exported by js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/bases), including `base58btc`, `base32` and others.
27
42
28
-
## Adding additional codecs
43
+
Additional bases can be configured using the `bases` config property.
44
+
45
+
## Adding additional BlockCodecs, Multihashes and Multibases
29
46
30
47
If your application requires support for extra codecs, you can configure them as follows:
31
48
@@ -35,14 +52,34 @@ If your application requires support for extra codecs, you can configure them as
35
52
36
53
constnode=awaitipfs({
37
54
ipld: {
38
-
// either specify them as part of the `formats` list
39
-
formats: [
40
-
require('my-format')
55
+
// either specify BlockCodecs as part of the `codecs` list
56
+
codecs: [
57
+
require('custom-blockcodec')
41
58
],
42
59
43
-
// or supply a function to load them dynamically
44
-
loadFormat:async (format) => {
45
-
returnrequire(format)
60
+
// and/or supply a function to load them dynamically
61
+
loadCodec:async (codecNameOrCode) => {
62
+
returnrequire(codecNameOrCode)
63
+
},
64
+
65
+
// either specify Multibase codecs as part of the `bases` list
66
+
bases: [
67
+
require('custom-multibase')
68
+
],
69
+
70
+
// and/or supply a function to load them dynamically
71
+
loadBase:async (baseNameOrCode) => {
72
+
returnrequire(baseNameOrCode)
73
+
},
74
+
75
+
// either specify Multihash hashers as part of the `hashers` list
76
+
hashers: [
77
+
require('custom-multibase')
78
+
],
79
+
80
+
// and/or supply a function to load them dynamically
81
+
loadHasher:async (hashNameOrCode) => {
82
+
returnrequire(hashNameOrCode)
46
83
}
47
84
}
48
85
})
@@ -53,14 +90,34 @@ If your application requires support for extra codecs, you can configure them as
53
90
const client = ipfsHttpClient({
54
91
url: 'http://127.0.0.1:5002',
55
92
ipld: {
56
-
// either specify them as part of the `formats` list
57
-
formats: [
58
-
require('my-format')
93
+
// either specify BlockCodecs as part of the `codecs` list
94
+
codecs: [
95
+
require('custom-blockcodec')
96
+
],
97
+
98
+
// and/or supply a function to load them dynamically
99
+
loadCodec: async (codecNameOrCode) => {
100
+
return require(codecNameOrCode)
101
+
},
102
+
103
+
// either specify Multibase codecs as part of the `bases` list
104
+
bases: [
105
+
require('custom-multibase')
59
106
],
60
107
61
-
// or supply a function to load them dynamically
62
-
loadFormat: async (format) => {
63
-
return require(format)
108
+
// and/or supply a function to load them dynamically
109
+
loadBase: async (baseNameOrCode) => {
110
+
return require(baseNameOrCode)
111
+
},
112
+
113
+
// either specify Multihash hashers as part of the `hashers` list
114
+
hashers: [
115
+
require('custom-multibase')
116
+
],
117
+
118
+
// and/or supply a function to load them dynamically
119
+
loadHasher: async (hashNameOrCode) => {
120
+
return require(hashNameOrCode)
64
121
}
65
122
}
66
123
})
@@ -69,7 +126,11 @@ If your application requires support for extra codecs, you can configure them as
69
126
## Next steps
70
127
71
128
* See [examples/custom-ipld-formats](https://github.com/ipfs/js-ipfs/tree/master/examples/custom-ipld-formats) for runnable code that demonstrates the above with in-process IPFS nodes, IPFS run as a daemon and also the http client
129
+
* Also [examples/traverse-ipld-graphs](https://github.com/ipfs/js-ipfs/tree/master/examples/traverse-ipld-graphs) which uses the [ipld-format-to-blockcodec](https://www.npmjs.com/package/ipld-format-to-blockcodec) module to use older [IPLD format][]s that have not been ported over to the new [BlockCodec][] interface, as well as additional [Multihash Hashers](https://www.npmjs.com/package/multiformats#multihash-hashers).
0 commit comments