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

Commit 80edc88

Browse files
committed
Add ipfs.files.add documentation.
1 parent cdc7467 commit 80edc88

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

README.md

+81-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,86 @@ 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+
content: (Buffer or Readable stream)
75+
}
76+
```
77+
- a `Buffer` instance
78+
- a `Readable` stream
79+
80+
`callback` must follow `function (err, res) {}` signature, where `err` is an
81+
error if the operation was not successful. `res` will be an array of
82+
[DAGNode][]s.
83+
84+
If no `callback` is passed, a promise is returned.
85+
86+
```js
87+
var files = [
88+
{
89+
path: '/tmp/myfile.txt',
90+
content: fs.createReadStream('/tmp/myfile.txt')
91+
}
92+
]
93+
ipfs.files.add(files, function (err, dagNodes) {
94+
// 'res' will be an array of DAGNodes
95+
})
96+
```
97+
98+
99+
### `createAddStream`
100+
101+
> Add files and data to IPFS using a transform stream.
102+
103+
##### `Go` **WIP**
104+
105+
##### `JavaScript` - ipfs.files.createAddStream([callback])
106+
107+
Provides a Transform stream, where objects can be written of the forms
108+
109+
```js
110+
{
111+
path: '/tmp/myfile.txt',
112+
content: (Buffer or Readable stream)
113+
}
114+
```
115+
116+
`callback` must follow `function (err, stream) {}` signature, where `err` is an
117+
error if the operation was not successful. `stream` will be a Transform stream,
118+
to which tuples like the above two object formats can be written and [DAGNode][]
119+
objects will be outputted.
120+
121+
If no `callback` is passed, a promise is returned.
122+
123+
```js
124+
ipfs.files.createAddStream(function (err, stream) {
125+
stream.on('data', function (dagNode) {
126+
// ...
127+
})
128+
129+
stream.write({path: <path to file>, content: <buffer or readable stream>})
130+
// write as many as you want
131+
132+
stream.end()
133+
})
134+
```
135+
136+
137+
58138
## Object
59139

60140
### `object.new`

0 commit comments

Comments
 (0)