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

Commit c6fb17e

Browse files
committed
feat: addFromFs addFromUrl and addFromStream APIs
1 parent 171d9e9 commit c6fb17e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

SPEC/FILES.md

+69
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,75 @@ pull(
221221
)
222222
```
223223

224+
#### `addFromFs`
225+
226+
> Add files or entire directories from the FileSystem to IPFS
227+
228+
##### `Go` **WIP**
229+
230+
##### `JavaScript` - ipfs.addFromFs(path, [option], [callback])
231+
232+
Reads a file or folder from `path` on the filesystem and adds it to IPFS. Options:
233+
- **recursive**: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
234+
- **ignore**: To exclude fileglobs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
235+
- **hidden**: hidden/dot files (files or folders starting with a `.`, for example, `.git/`) are not included by default. To add them, use the option `{ hidden: true }`.
236+
237+
```JavaScript
238+
ipfs.addFromFs('path/to/a/folder', { recursive: true , ignore: ['subfolder/to/ignore/**']}, (err, result) => {
239+
if (err) { throw err }
240+
console.log(result)
241+
})
242+
```
243+
244+
`result` is an array of objects describing the files that were added, such as:
245+
246+
```js
247+
[
248+
{
249+
path: 'test-folder',
250+
hash: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6',
251+
size: 2278
252+
},
253+
// ...
254+
]
255+
```
256+
257+
#### `addFromUrl
258+
259+
> Add a file from a URL to IPFS
260+
261+
##### `Go` **WIP**
262+
263+
##### `JavaScript` - ipfs.addFromURL(url, callback)
264+
265+
```JavaScript
266+
ipfs.addFromURL('http://example.com/', (err, result) => {
267+
if (err) {
268+
throw err
269+
}
270+
console.log(result)
271+
})
272+
```
273+
274+
#### `addFromUrl`
275+
276+
> Add a file from a stream to IPFS
277+
278+
##### `Go` **WIP**
279+
280+
##### `JavaScript` - ipfs.addFromStream(stream, callback)
281+
282+
This is very similar to `ipfs.files.add({path:'', content: stream})`. It is like the reverse of cat
283+
284+
```JavaScript
285+
ipfs.addFromStream(<readable-stream>, (err, result) => {
286+
if (err) {
287+
throw err
288+
}
289+
console.log(result)
290+
})
291+
```
292+
224293
#### `cat`
225294

226295
> Returns a file addressed by a valid IPFS Path.

0 commit comments

Comments
 (0)