Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit aa193d5

Browse files
committed
files api tests
1 parent 3eb3462 commit aa193d5

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,38 @@ curl 'http://localhost:5001/api/v0/object/get?arg=QmYEqnfCZp7a39Gxrgyv3qRS4MoCTG
217217
#### Pin
218218

219219
#### Gateway
220+
221+
#### Files
222+
223+
##### mkdir
224+
225+
bash:
226+
`curl "http://localhost:5001/api/v0/files/mkdir?arg=%2F<folder name>`"
227+
228+
response: (it returns empty when successful)
229+
```
230+
```
231+
232+
javascript:
233+
```JavaScript
234+
ipfs.files.mkdir(<folderName>, function (err) {})
235+
```
236+
237+
response: (it returns empty when successful)
238+
```
239+
```
240+
241+
##### cp
242+
243+
##### ls
244+
245+
##### stat
246+
247+
##### rm
248+
249+
##### read
250+
251+
##### write
252+
253+
##### mv
254+
curl "http://localhost:5001/api/v0/files/mkdir?arg=%2Ffolder4"

examples/files-api.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var ipfs = require('../src')('localhost', 5001)
2+
3+
ipfs.files.ls('/folder1', function (err, res) {
4+
if (err) {
5+
return console.log(err)
6+
}
7+
if (res.readable) {
8+
res.pipe(process.stdout)
9+
} else {
10+
console.log(res)
11+
}
12+
})

src/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,21 @@ function IpfsAPI (host_or_multiaddr, port) {
239239
return requestAPI('dht/put', [key, value], opts, null, cb)
240240
}
241241
}
242+
243+
self.files = {
244+
cp: argCommand('files/cp'),
245+
ls: argCommand('files/ls'),
246+
mkdir: argCommand('files/mkdir'),
247+
stat: argCommand('files/stat'),
248+
rm: function (key, value, opts, cb) {
249+
if (typeof (opts) === 'function') {
250+
cb = opts
251+
opts = {}
252+
}
253+
return requestAPI('config', [key, value], opts, null, cb)
254+
},
255+
read: argCommand('files/read'),
256+
write: argCommand('files/write'),
257+
mv: argCommand('files/mv')
258+
}
242259
}

0 commit comments

Comments
 (0)