@@ -25,7 +25,7 @@ interface-ipfs-core API.
25
25
26
26
![ ] ( /img/badge.png )
27
27
28
- # How to use the battery tests
28
+ # How to use the battery of tests
29
29
30
30
## Node.js
31
31
@@ -55,6 +55,73 @@ test.all(common)
55
55
56
56
A valid (read: that follows this interface) IPFS core implementation, must expose the following API.
57
57
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
+
58
125
## Object
59
126
60
127
### ` object.new `
0 commit comments