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 Mar 10, 2020. It is now read-only.
refactor: object API write methods return CIDs (#399)
Since `ipld-dag-pb` removed `multihash` and `cid` properties, the Object API became less useful, returning the data you provided it when you call methods that write DAG nodes. This meant the user had to calculate the CID manually.
This PR updates the Object API so that write methods return CID instances instead of DAG nodes.
See discussion here for more context: #388 (review)
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
`template` if defined, must be a string `unixfs-dir` and if that is passed, the created node will be an empty unixfs style directory.
23
23
24
-
`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][]
24
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of [CID][].
25
25
26
26
If no `callback` is passed, a [promise][] is returned.
27
27
28
28
**Example:**
29
29
30
30
```JavaScript
31
-
ipfs.object.new('unixfs-dir', (err, node) => {
31
+
ipfs.object.new('unixfs-dir', (err, cid) => {
32
32
if (err) {
33
33
throw err
34
34
}
35
-
console.log(node.toJSON().multihash)
35
+
console.log(cid.toString())
36
36
// Logs:
37
37
// QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
38
38
})
@@ -46,7 +46,7 @@ A great source of [examples][] can be found in the tests for this API.
`obj` is the MerkleDAG Node to be stored. Can of type:
52
52
@@ -58,7 +58,7 @@ A great source of [examples][] can be found in the tests for this API.
58
58
59
59
-`enc`, the encoding of the Buffer (json, yml, etc), if passed a Buffer.
60
60
61
-
`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][]
61
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of [CID][].
62
62
63
63
If no `callback` is passed, a [promise][] is returned.
64
64
@@ -70,11 +70,11 @@ const obj = {
70
70
Links: []
71
71
}
72
72
73
-
ipfs.object.put(obj, (err, node) => {
73
+
ipfs.object.put(obj, (err, cid) => {
74
74
if (err) {
75
75
throw err
76
76
}
77
-
console.log(node.toJSON().multihash)
77
+
console.log(cid.toString())
78
78
// Logs:
79
79
// QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK
80
80
})
@@ -88,7 +88,7 @@ A great source of [examples][] can be found in the tests for this API.
`multihash` is a [multihash][] which can be passed as:
267
267
@@ -290,7 +290,7 @@ const link = new DAGLink(name, size, multihash)
290
290
291
291
-`enc`, the encoding of multihash (base58, base64, etc), if any.
292
292
293
-
`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.
293
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of [CID][]- the CID of the new DAG node that was created due to the operation.
294
294
295
295
If no `callback` is passed, a [promise][] is returned.
`options` is a optional argument of type object, that can contain the following properties:
344
344
345
345
-`enc`, the encoding ofmultihash (base58, base64, etc), if any.
346
346
347
-
`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.
347
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of[CID][] - the CIDofthe newDAG node that was created due to the operation.
348
348
349
349
If no `callback` is passed, a [promise][] is returned.
350
350
@@ -361,7 +361,7 @@ A great source of [examples][] can be found in the tests for this API.
`multihash` is a [multihash][] which can be passed as:
367
367
@@ -374,7 +374,7 @@ A great source of [examples][] can be found in the tests for this API.
374
374
375
375
-`enc`, the encoding ofmultihash (base58, base64, etc), if any.
376
376
377
-
`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.
377
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of[CID][] - the CIDofthe newDAG node that was created due to the operation.
378
378
379
379
If no `callback` is passed, a [promise][] is returned.
380
380
@@ -396,7 +396,7 @@ A great source of [examples][] can be found in the tests for this API.
`multihash` is a [multihash][] which can be passed as:
402
402
@@ -409,23 +409,23 @@ A great source of [examples][] can be found in the tests for this API.
409
409
410
410
-`enc`, the encoding ofmultihash (base58, base64, etc), if any.
411
411
412
-
`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.
412
+
`callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and `cid` is an instance of[CID][] - the CIDofthe newDAG node that was created due to the operation.
413
413
414
414
If no `callback` is passed, a [promise][] is returned.
0 commit comments