forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-path.js
48 lines (36 loc) · 856 Bytes
/
get-path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
const createNode = require('./create-node.js')
createNode((err, ipfs) => {
if (err) {
throw err
}
console.log('\nStart of the example:')
const myData = {
name: 'David',
likes: ['js-ipfs', 'icecream', 'steak']
}
ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
throw err
}
ipfs.dag.get(cid, 'name', (err, result) => {
if (err) {
throw err
}
console.log(result.value, result.remainderPath)
})
ipfs.dag.get(cid, 'likes', (err, result) => {
if (err) {
throw err
}
console.log(result.value)
})
const cidStr = cid.toBaseEncodedString()
ipfs.dag.get(cidStr + '/likes/0', (err, result) => {
if (err) {
throw err
}
console.log(result.value)
})
})
})