|
| 1 | +object API |
| 2 | +========== |
| 3 | + |
| 4 | +#### `object.new` |
| 5 | + |
| 6 | +> Create a new MerkleDAG node, using a specific layout. Caveat: So far, only UnixFS object layouts are supported. |
| 7 | +
|
| 8 | +##### `Go` **WIP** |
| 9 | + |
| 10 | +##### `JavaScript` - ipfs.object.new([callback]) |
| 11 | + |
| 12 | +`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][] |
| 13 | + |
| 14 | +If no `callback` is passed, a [promise][] is returned. |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +#### `object.put` |
| 21 | + |
| 22 | +> Store an MerkleDAG node. |
| 23 | +
|
| 24 | +##### `Go` **WIP** |
| 25 | + |
| 26 | +##### `JavaScript` - ipfs.object.put(obj, [options, callback]) |
| 27 | + |
| 28 | +`obj` is the MerkleDAG Node to be stored. Can of type: |
| 29 | + |
| 30 | +- Object, with format `{ Data: <data>, Links: [] }` |
| 31 | +- Buffer, requiring that the encoding is specified on the options. If no encoding is specified, Buffer is treated as the Data field |
| 32 | +- [DAGNode][] |
| 33 | + |
| 34 | +`options` is a optional argument of type object, that can contain the following properties: |
| 35 | + |
| 36 | +- `enc`, the encoding of the Buffer (json, yml, etc), if passed a Buffer. |
| 37 | + |
| 38 | +`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][] |
| 39 | + |
| 40 | +If no `callback` is passed, a [promise][] is returned. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +#### `object.get` |
| 47 | + |
| 48 | +> Fetch a MerkleDAG node |
| 49 | +
|
| 50 | +##### `Go` **WIP** |
| 51 | + |
| 52 | +##### `JavaScript` - ipfs.object.get(multihash, [options, callback]) |
| 53 | + |
| 54 | +`multihash` is a [multihash][] which can be passed as: |
| 55 | + |
| 56 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 57 | +- String, the toString version of the multihash (or of an encoded version) |
| 58 | + |
| 59 | +`options` is a optional argument of type object, that can contain the following properties: |
| 60 | + |
| 61 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 62 | + |
| 63 | +`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][] |
| 64 | + |
| 65 | +If no `callback` is passed, a [promise][] is returned. |
| 66 | + |
| 67 | +#### `object.data` |
| 68 | + |
| 69 | +> Returns the Data field of an object |
| 70 | +
|
| 71 | +##### `Go` **WIP** |
| 72 | + |
| 73 | +##### `JavaScript` - ipfs.object.data(multihash, [options, callback]) |
| 74 | +`multihash` is a [multihash][] which can be passed as: |
| 75 | + |
| 76 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 77 | +- String, the toString version of the multihash (or of an encoded version) |
| 78 | + |
| 79 | +`options` is a optional argument of type object, that can contain the following properties: |
| 80 | + |
| 81 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 82 | + |
| 83 | +`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. |
| 84 | + |
| 85 | +If no `callback` is passed, a [promise][] is returned. |
| 86 | + |
| 87 | +#### `object.links` |
| 88 | + |
| 89 | +> Returns the Links field of an object |
| 90 | +
|
| 91 | +##### `Go` **WIP** |
| 92 | + |
| 93 | +##### `JavaScript` - ipfs.object.links(multihash, [options, callback]) |
| 94 | + |
| 95 | +`multihash` is a [multihash][] which can be passed as: |
| 96 | + |
| 97 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 98 | +- String, the toString version of the multihash (or of an encoded version) |
| 99 | + |
| 100 | +`options` is a optional argument of type object, that can contain the following properties: |
| 101 | + |
| 102 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 103 | + |
| 104 | +`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. |
| 105 | + |
| 106 | +If no `callback` is passed, a [promise][] is returned. |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +#### `object.stat` |
| 113 | + |
| 114 | +> Returns stats about an Object |
| 115 | +
|
| 116 | +##### `Go` **WIP** |
| 117 | + |
| 118 | +##### `JavaScript` - ipfs.object.stat(multihash, [options, callback]) |
| 119 | + |
| 120 | +`multihash` is a [multihash][] which can be passed as: |
| 121 | + |
| 122 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 123 | +- String, the toString version of the multihash (or of an encoded version) |
| 124 | + |
| 125 | +`options` is a optional argument of type object, that can contain the following properties: |
| 126 | + |
| 127 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 128 | + |
| 129 | +`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: |
| 130 | + |
| 131 | +```JavaScript |
| 132 | +{ |
| 133 | + Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD', |
| 134 | + NumLinks: 0, |
| 135 | + BlockSize: 10, |
| 136 | + LinksSize: 2, |
| 137 | + DataSize: 8, |
| 138 | + CumulativeSize: 10 |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +If no `callback` is passed, a [promise][] is returned. |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | +#### `object.patch` |
| 149 | + |
| 150 | +> `object.patch` exposes the available patch calls. |
| 151 | +
|
| 152 | +##### `object.patch.addLink` |
| 153 | + |
| 154 | +> Add a Link to an existing MerkleDAG Object |
| 155 | +
|
| 156 | +###### `Go` **WIP** |
| 157 | + |
| 158 | +###### `JavaScript` - ipfs.object.patch.addLink(multihash, DAGLink, [options, callback]) |
| 159 | + |
| 160 | +`multihash` is a [multihash][] which can be passed as: |
| 161 | + |
| 162 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 163 | +- String, the toString version of the multihash (or of an encoded version) |
| 164 | + |
| 165 | +`DAGLink` is the new link to be added on the node that is identified by the `multihash` |
| 166 | + |
| 167 | +`options` is a optional argument of type object, that can contain the following properties: |
| 168 | + |
| 169 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 170 | + |
| 171 | +`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][] that resulted by the operation of adding a Link. |
| 172 | + |
| 173 | +If no `callback` is passed, a [promise][] is returned. |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | +##### `object.patch.rmLink` |
| 180 | + |
| 181 | +> Remove a Link from an existing MerkleDAG Object |
| 182 | +
|
| 183 | +###### `Go` **WIP** |
| 184 | + |
| 185 | +###### `JavaScript` - ipfs.object.patch.rmLink(multihash, DAGLink, [options, callback]) |
| 186 | + |
| 187 | +`multihash` is a [multihash][] which can be passed as: |
| 188 | + |
| 189 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 190 | +- String, the toString version of the multihash (or of an encoded version) |
| 191 | + |
| 192 | +`DAGLink` is the link to be removed on the node that is identified by the `multihash` |
| 193 | + |
| 194 | +`options` is a optional argument of type object, that can contain the following properties: |
| 195 | + |
| 196 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 197 | + |
| 198 | +`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][] that resulted by the operation of adding a Link. |
| 199 | + |
| 200 | +If no `callback` is passed, a [promise][] is returned. |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +##### `object.patch.appendData` |
| 207 | + |
| 208 | +> Append Data to the Data field of an existing node. |
| 209 | +
|
| 210 | +###### `Go` **WIP** |
| 211 | + |
| 212 | +###### `JavaScript` - ipfs.object.patch.appendData(multihash, data, [options, callback]) |
| 213 | + |
| 214 | +`multihash` is a [multihash][] which can be passed as: |
| 215 | + |
| 216 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 217 | +- String, the toString version of the multihash (or of an encoded version) |
| 218 | + |
| 219 | +`data` is a Buffer containing Data to be appended to the existing node. |
| 220 | + |
| 221 | +`options` is a optional argument of type object, that can contain the following properties: |
| 222 | + |
| 223 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 224 | + |
| 225 | +`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][] that resulted by the operation of adding a Link. |
| 226 | + |
| 227 | +If no `callback` is passed, a [promise][] is returned. |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | +##### `object.patch.setData` |
| 234 | + |
| 235 | +> Reset the Data field of a MerkleDAG Node to new Data |
| 236 | +
|
| 237 | +###### `Go` **WIP** |
| 238 | + |
| 239 | +###### `JavaScript` - ipfs.object.patch.setData(multihash, data, [options, callback]) |
| 240 | + |
| 241 | +`multihash` is a [multihash][] which can be passed as: |
| 242 | + |
| 243 | +- Buffer, the raw Buffer of the multihash (or of and encoded version) |
| 244 | +- String, the toString version of the multihash (or of an encoded version) |
| 245 | + |
| 246 | +`data` is a Buffer containing Data to replace the existing Data on the node. |
| 247 | + |
| 248 | +`options` is a optional argument of type object, that can contain the following properties: |
| 249 | + |
| 250 | +- `enc`, the encoding of multihash (base58, base64, etc), if any. |
| 251 | + |
| 252 | +`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][] that resulted by the operation of adding a Link. |
| 253 | + |
| 254 | +If no `callback` is passed, a [promise][] is returned. |
| 255 | + |
| 256 | +[DAGNode]: https://github.com/vijayee/js-ipfs-merkle-dag |
| 257 | +[multihash]: http://github.com/jbenet/multihash |
| 258 | +[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise |
| 259 | + |
| 260 | + |
0 commit comments