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

Commit 8e0f8f2

Browse files
committed
Add ipfs.files.add documentation.
1 parent cdc7467 commit 8e0f8f2

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

README.md

+68-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface-ipfs-core API.
2525

2626
![](/img/badge.png)
2727

28-
# How to use the battery tests
28+
# How to use the battery of tests
2929

3030
## Node.js
3131

@@ -55,6 +55,73 @@ test.all(common)
5555

5656
A valid (read: that follows this interface) IPFS core implementation, must expose the following API.
5757

58+
## Files
59+
60+
### `add`
61+
62+
> Add files and data to IPFS.
63+
64+
##### `Go` **WIP**
65+
66+
##### `JavaScript` - ipfs.files.add(data, [callback])
67+
68+
Where `data` may be
69+
70+
- an array of objects, each of the form
71+
```js
72+
{
73+
path: '/tmp/myfile.txt',
74+
stream: fs.createReadStream('/tmp/myfile.txt')
75+
}
76+
```
77+
- an array of objects, each of the form
78+
```js
79+
{
80+
path: '/tmp/myfile.txt',
81+
content: new Buffer('hello')
82+
}
83+
```
84+
- a `Buffer` instance
85+
- a Readable stream
86+
87+
`callback` must follow `function (err, res) {}` signature, where `err` is an
88+
error if the operation was not successful. If no value `data` is provided, `res`
89+
will be a Duplex stream, to which tuples like the above two object formats can
90+
be written and [DAGNode][] objects will be outputted. Otherwise, `res` will be
91+
an array of [DAGNode][]s.
92+
93+
If no `callback` is passed, a promise is returned.
94+
95+
```js
96+
// array in => array out
97+
var files = [
98+
{
99+
path: '/tmp/myfile.txt',
100+
stream: fs.createReadStream('/tmp/myfile.txt')
101+
}
102+
]
103+
ipfs.files.add(files, function (err, dagNodes) {
104+
// 'res' will be an array of DAGNodes
105+
})
106+
```
107+
108+
```js
109+
// no input => duplex stream out
110+
ipfs.files.add(function (err, stream) {
111+
stream.on('data', function (dagNode) {
112+
// ...
113+
})
114+
115+
stream.write({path: <path to file>, stream: <readable stream>})
116+
// write as many as you want
117+
118+
stream.end()
119+
})
120+
```
121+
122+
123+
124+
58125
## Object
59126

60127
### `object.new`

0 commit comments

Comments
 (0)