|
1 |
| -# interface-ipfs-core |
2 |
| -A test suite and interface you can use to implement a IPFS core interface. |
| 1 | +interface-ipfs-core |
| 2 | +=================== |
| 3 | + |
| 4 | +[](http://ipn.io) |
| 5 | +[](http://webchat.freenode.net/?channels=%23ipfs) |
| 6 | + |
| 7 | +> A test suite and interface you can use to implement the IPFS Core API. |
| 8 | +
|
| 9 | +The primary goal of this module is to define and ensure that both IPFS core implementations and their respective HTTP client libraries offer the same interface, so that developers can quickly change between a local and a remote node without having to change their applications. In addition to the definition of the expected interface, this module offers a suite of tests that can be run in order to check if the interface is used as described. |
| 10 | + |
| 11 | +The API is presented with both Node.js and Go primitives, however, there is not actual limitations for it to be extended for any other language, pushing forward the cross compatibility and interop through diferent stacks. |
| 12 | + |
| 13 | +# Modules that implement the interface |
| 14 | + |
| 15 | +- [JavaScript IPFS implementation](https://github.com/ipfs/js-ipfs) |
| 16 | +- [JavaScript ipfs-api](https://github.com/ipfs/js-ipfs-api) |
| 17 | +- Soon, go-ipfs, go-ipfs-api, java-ipfs-api, python-ipfs-api and others will implement it as well. |
| 18 | + |
| 19 | +Send a PR to add a new one if you happen to find or write one. |
| 20 | + |
| 21 | +# Badge |
| 22 | + |
| 23 | +Include this badge in your readme if you make a new module that uses interface-stream-muxer API. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +# How to use the battery tests |
| 28 | + |
| 29 | +## Node.js |
| 30 | + |
| 31 | +Install interface-ipfs-core as one of the dependencies of your project and as a test file, using `mocha` (for Node.js) or a test runner with compatible API, do: |
| 32 | + |
| 33 | +``` |
| 34 | +var test = require('interface-ipfs-core') |
| 35 | +
|
| 36 | +var common = { |
| 37 | + setup: function (cb) { |
| 38 | + cb(null, yourIPFSInstance) |
| 39 | + }, |
| 40 | + teardown: function (cb) { |
| 41 | + cb() |
| 42 | + } |
| 43 | +} |
| 44 | +
|
| 45 | +// use all of the test suits |
| 46 | +test.all(common) |
| 47 | +``` |
| 48 | + |
| 49 | +## Go |
| 50 | + |
| 51 | +> WIP |
| 52 | +
|
| 53 | +# API |
| 54 | + |
| 55 | +A valid (read: that follows this interface) IPFS core implementation, must expose the following API. |
| 56 | + |
| 57 | +## Object |
| 58 | + |
| 59 | +### `object.new` |
| 60 | + |
| 61 | +> Create a new MerkleDAG node, using a specific layout. Caveat: So far, only UnixFS object layouts are supported. |
| 62 | +
|
| 63 | +##### `Go` **WIP** |
| 64 | + |
| 65 | +##### `JavaScript` - ipfs.object.new(layout, [callback]) |
| 66 | + |
| 67 | +`layout` is the MerkleDAG node type, it can be: `null`, `'unixfs-dir'`, `'unixfs-raw'`, `'unixfs-file'`, `'unixfs-metadata'`, `'unixfs-symlink'`. |
| 68 | + |
| 69 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) |
| 70 | + |
| 71 | +If no `callback` is passed, a promise is returned. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +### `object.put` |
| 78 | + |
| 79 | +> Store an MerkleDAG node. |
| 80 | +
|
| 81 | +##### `Go` **WIP** |
| 82 | + |
| 83 | +##### `JavaScript` - ipfs.object.put(obj, [options, callback]) |
| 84 | + |
| 85 | +`obj` is the MerkleDAG Node to be stored. Can of type: |
| 86 | + |
| 87 | +- Object, with format `{ Data: <data>, Links: [] }` |
| 88 | +- Buffer, requiring that the encoding is specified on the encoding |
| 89 | +- [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js). If no encoding is specified, Buffer is treated as the Data field. |
| 90 | + |
| 91 | +`options` is a optional argument of type object, that can contain the following properties: |
| 92 | + |
| 93 | +- `enc`, the encoding of the Buffer (json, yml, etc), if passed a Buffer. |
| 94 | + |
| 95 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) |
| 96 | + |
| 97 | +If no `callback` is passed, a promise is returned. |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +### `object.get` |
| 104 | + |
| 105 | +> Fetch a MerkleDAG node |
| 106 | +
|
| 107 | +##### `Go` **WIP** |
| 108 | + |
| 109 | +##### `JavaScript` - ipfs.object.get(multihash, [options, callback]) |
| 110 | + |
| 111 | +`multihash` is a [multihash]() which can be passed as: |
| 112 | + |
| 113 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 114 | +- String, the toString version of the multihash (or of an encoded version) |
| 115 | + |
| 116 | +`options` is a optional argument of type object, that can contain the following properties: |
| 117 | + |
| 118 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 119 | + |
| 120 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) |
| 121 | + |
| 122 | +If no `callback` is passed, a promise is returned. |
| 123 | + |
| 124 | +### `object.data` |
| 125 | + |
| 126 | +> Returns the Data field of an object |
| 127 | +
|
| 128 | +##### `Go` **WIP** |
| 129 | + |
| 130 | +##### `JavaScript` - ipfs.object.data(multihash, [options, callback]) |
| 131 | +`multihash` is a [multihash]() which can be passed as: |
| 132 | + |
| 133 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 134 | +- String, the toString version of the multihash (or of an encoded version) |
| 135 | + |
| 136 | +`options` is a optional argument of type object, that can contain the following properties: |
| 137 | + |
| 138 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 139 | + |
| 140 | +`callback` must follow `function (err, data) {}` signature, where `err` is an error if the operation was not successful and `data` is a Buffer with the data that the MerkleDAG node contained. |
| 141 | + |
| 142 | +If no `callback` is passed, a promise is returned. |
| 143 | + |
| 144 | +### `object.links` |
| 145 | + |
| 146 | +> Returns the Links field of an object |
| 147 | +
|
| 148 | +##### `Go` **WIP** |
| 149 | + |
| 150 | +##### `JavaScript` - ipfs.object.links(multihash, [options, callback]) |
| 151 | + |
| 152 | +`multihash` is a [multihash]() which can be passed as: |
| 153 | + |
| 154 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 155 | +- String, the toString version of the multihash (or of an encoded version) |
| 156 | + |
| 157 | +`options` is a optional argument of type object, that can contain the following properties: |
| 158 | + |
| 159 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 160 | + |
| 161 | +`callback` must follow `function (err, links) {}` signature, where `err` is an error if the operation was not successful and `links` is an Array of [DAGLink](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js#L199-L203) objects. |
| 162 | + |
| 163 | +If no `callback` is passed, a promise is returned. |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +### `object.stat` |
| 170 | + |
| 171 | +> Returns stats about an Object |
| 172 | +
|
| 173 | +##### `Go` **WIP** |
| 174 | + |
| 175 | +##### `JavaScript` - ipfs.object.stat(multihash, [options, callback]) |
| 176 | + |
| 177 | +`multihash` is a [multihash]() which can be passed as: |
| 178 | + |
| 179 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 180 | +- String, the toString version of the multihash (or of an encoded version) |
| 181 | + |
| 182 | +`options` is a optional argument of type object, that can contain the following properties: |
| 183 | + |
| 184 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 185 | + |
| 186 | +`callback` must follow `function (err, stats) {}` signature, where `err` is an error if the operation was not successful and `stats` is an Object with following format: |
| 187 | + |
| 188 | +```JavaScript |
| 189 | +{ |
| 190 | + Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD', |
| 191 | + NumLinks: 0, |
| 192 | + BlockSize: 10, |
| 193 | + LinksSize: 2, |
| 194 | + DataSize: 8, |
| 195 | + CumulativeSize: 10 |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +If no `callback` is passed, a promise is returned. |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | +### `object.patch` |
| 206 | + |
| 207 | +> `object.patch` exposes the available patch calls. |
| 208 | +
|
| 209 | +#### `object.patch.addLink` |
| 210 | + |
| 211 | +> Add a Link to an existing MerkleDAG Object |
| 212 | +
|
| 213 | +##### `Go` **WIP** |
| 214 | + |
| 215 | +##### `JavaScript` - ipfs.object.patch.addLink(multihash, DAGLink, [options, callback]) |
| 216 | + |
| 217 | +`multihash` is a [multihash]() which can be passed as: |
| 218 | + |
| 219 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 220 | +- String, the toString version of the multihash (or of an encoded version) |
| 221 | + |
| 222 | +`DAGLink` is the new link to be added on the node that is identified by the `multihash` |
| 223 | + |
| 224 | +`options` is a optional argument of type object, that can contain the following properties: |
| 225 | + |
| 226 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 227 | + |
| 228 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) that resulted by the operation of adding a Link. |
| 229 | + |
| 230 | +If no `callback` is passed, a promise is returned. |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | +#### `object.patch.rmLink` |
| 237 | + |
| 238 | +> Remove a Link from an existing MerkleDAG Object |
| 239 | +
|
| 240 | +##### `Go` **WIP** |
| 241 | + |
| 242 | +##### `JavaScript` - ipfs.object.patch.rmLink(multihash, DAGLink, [options, callback]) |
| 243 | + |
| 244 | +`multihash` is a [multihash]() which can be passed as: |
| 245 | + |
| 246 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 247 | +- String, the toString version of the multihash (or of an encoded version) |
| 248 | + |
| 249 | +`DAGLink` is the link to be removed on the node that is identified by the `multihash` |
| 250 | + |
| 251 | +`options` is a optional argument of type object, that can contain the following properties: |
| 252 | + |
| 253 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 254 | + |
| 255 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) that resulted by the operation of adding a Link. |
| 256 | + |
| 257 | +If no `callback` is passed, a promise is returned. |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | +#### `object.patch.appendData` |
| 264 | + |
| 265 | +> Append Data to the Data field of an existing node. |
| 266 | +
|
| 267 | +##### `Go` **WIP** |
| 268 | + |
| 269 | +##### `JavaScript` - ipfs.object.patch.appendData(multihash, data, [options, callback]) |
| 270 | + |
| 271 | +`multihash` is a [multihash]() which can be passed as: |
| 272 | + |
| 273 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 274 | +- String, the toString version of the multihash (or of an encoded version) |
| 275 | + |
| 276 | +`data` is a Buffer containing Data to be appended to the existing node. |
| 277 | + |
| 278 | +`options` is a optional argument of type object, that can contain the following properties: |
| 279 | + |
| 280 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 281 | + |
| 282 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) that resulted by the operation of adding a Link. |
| 283 | + |
| 284 | +If no `callback` is passed, a promise is returned. |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | +#### `object.patch.setData` |
| 291 | + |
| 292 | +> Reset the Data field of a MerkleDAG Node to new Data |
| 293 | +
|
| 294 | +##### `Go` **WIP** |
| 295 | + |
| 296 | +##### `JavaScript` - ipfs.object.patch.setData(multihash, data, [options, callback]) |
| 297 | + |
| 298 | +`multihash` is a [multihash]() which can be passed as: |
| 299 | + |
| 300 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 301 | +- String, the toString version of the multihash (or of an encoded version) |
| 302 | + |
| 303 | +`data` is a Buffer containing Data to replace the existing Data on the node. |
| 304 | + |
| 305 | +`options` is a optional argument of type object, that can contain the following properties: |
| 306 | + |
| 307 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 308 | + |
| 309 | +`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) that resulted by the operation of adding a Link. |
| 310 | + |
| 311 | +If no `callback` is passed, a promise is returned. |
0 commit comments