Skip to content

Commit 51a5f33

Browse files
committed
add sub-module api example.(ipfs-inactive#544)
1 parent b906523 commit 51a5f33

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

examples/sub-module/sub-module.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
const files = require('../../src/files')('/ip4/127.0.0.1/tcp/5001')
4+
5+
files.cat('/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme', (err, res) => {
6+
if (err) {
7+
return console.error('Error fetching file', err)
8+
}
9+
10+
if (res.readable) {
11+
res.pipe(process.stdout)
12+
} else {
13+
console.log(res)
14+
}
15+
})

src/utils/module-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = (arg) => {
1515
const maddr = multiaddr(arg).nodeAddress()
1616
config.host = maddr.address
1717
config.port = maddr.port
18+
return requestAPI(config)
1819
} else {
1920
throw new Error('Argument must be a send function or a config object.')
2021
}

0 commit comments

Comments
 (0)