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

Commit 34f3658

Browse files
committed
Merge pull request #26 from ipfs/add
Interface for files.add
2 parents 9b8ba67 + 3bae1d8 commit 34f3658

15 files changed

+13772
-5
lines changed

README.md

Lines changed: 92 additions & 1 deletion
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,97 @@ 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+
83+
```js
84+
{
85+
path: '/tmp/myfile.txt',
86+
node: DAGNode
87+
}
88+
```
89+
90+
If no `callback` is passed, a promise is returned.
91+
92+
Example:
93+
```js
94+
var files = [
95+
{
96+
path: '/tmp/myfile.txt',
97+
content: (Buffer or Readable stream)
98+
}
99+
]
100+
ipfs.files.add(files, function (err, files) {
101+
// 'files' will be an array of objects
102+
})
103+
```
104+
105+
106+
### `createAddStream`
107+
108+
> Add files and data to IPFS using a transform stream.
109+
110+
##### `Go` **WIP**
111+
112+
##### `JavaScript` - ipfs.files.createAddStream([callback])
113+
114+
Provides a Transform stream, where objects can be written of the forms
115+
116+
```js
117+
{
118+
path: '/tmp/myfile.txt',
119+
content: (Buffer or Readable stream)
120+
}
121+
```
122+
123+
`callback` must follow `function (err, stream) {}` signature, where `err` is an
124+
error if the operation was not successful. `stream` will be a Transform stream,
125+
to which tuples like the above two object formats can be written and [DAGNode][]
126+
objects will be outputted.
127+
128+
If no `callback` is passed, a promise is returned.
129+
130+
```js
131+
ipfs.files.createAddStream(function (err, stream) {
132+
stream.on('data', function (file) {
133+
// 'file' will be of the form
134+
// {
135+
// path: '/tmp/myfile.txt',
136+
// node: DAGNode
137+
// }
138+
})
139+
140+
stream.write({path: <path to file>, content: <buffer or readable stream>})
141+
// write as many as you want
142+
143+
stream.end()
144+
})
145+
```
146+
147+
148+
58149
## Object
59150

60151
### `object.new`

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "interface-ipfs-core",
33
"version": "0.1.5",
44
"description": "A test suite and interface you can use to implement a IPFS core interface.",
5-
"main": "test/index.js",
6-
"jsnext:main": "test/index.js",
5+
"main": "lib/index.js",
6+
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "exit(0)",
99
"build": "aegir-build node",
@@ -28,9 +28,12 @@
2828
},
2929
"homepage": "https://github.com/ipfs/interface-ipfs-core#readme",
3030
"dependencies": {
31+
"bl": "^1.1.2",
3132
"bs58": "^3.0.0",
3233
"chai": "^3.5.0",
33-
"ipfs-merkle-dag": "^0.6.0"
34+
"detect-node": "^2.0.3",
35+
"ipfs-merkle-dag": "^0.6.0",
36+
"readable-stream": "1.1.13"
3437
},
3538
"devDependencies": {
3639
"aegir": "^3.2.0"
@@ -39,4 +42,4 @@
3942
"David Dias <[email protected]>",
4043
"Friedel Ziegelmayer <[email protected]>"
4144
]
42-
}
45+
}

src/data/15mb.random

14.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)