-
Notifications
You must be signed in to change notification settings - Fork 298
next generation #305
next generation #305
Changes from 15 commits
0534fa8
940c997
73078ea
108414b
43a1dfa
e5cb43c
11a166e
776cccd
ed07921
e97c567
ba0fc67
5d0a823
5f71752
4cffb47
2ae09fb
17f95fb
c0e66cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# js-ipfs-api | ||
ipfs-api | ||
======== | ||
|
||
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) | ||
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) | ||
|
@@ -9,7 +10,9 @@ | |
[![Travis CI](https://travis-ci.org/ipfs/js-ipfs-api.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs-api) | ||
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-api.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-api) | ||
|
||
> A client library for the IPFS HTTP API, implemented in JavaScript. | ||
> A client library for the IPFS HTTP API, implemented in JavaScript. This client library implements the [interface-ipfs-core](https://github.com/ipfs/interface-ipfs-core) enabling applications to change between a embebed js-ipfs node and any remove IPFS node without having to change the code. In addition, this client library implements a set of utility functions. | ||
|
||
![](https://github.com/ipfs/interface-ipfs-core/raw/master/img/badge.png) | ||
|
||
## Table of Contents | ||
|
||
|
@@ -102,16 +105,71 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"http://exam | |
|
||
### API | ||
|
||
> `WIP` | ||
|
||
`js-ipfs-api` follows the spec defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor - expect it to be complete in the next few weeks (August 2016). You can use it today to consult the methods available. | ||
> `js-ipfs-api` follows the spec defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor - expect it to be complete in the next few weeks (August 2016). You can use it today to consult the methods available. | ||
|
||
### Extra API methods | ||
### Utility functions | ||
|
||
Adding to the methods defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), `js-ipfs-api` exposes a set of extra utility methods. | ||
Adding to the methods defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), `js-ipfs-api` exposes a set of extra utility methods. These utility functions are scoped behind the `ipfs.util`. | ||
|
||
Complete documentation for these methods is coming with: https://github.com/ipfs/js-ipfs-api/pull/305 | ||
|
||
|
||
#### Add files or entire directories from the FileSystem to IPFS | ||
|
||
> `ipfs.util.fsAdd(path, option, callback)` | ||
|
||
Reads path from disk (if directory add an options `{ recursive: true }` and adds it to IPFS. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing ) after recursive: true. Might be better to word it as: Reads a file from |
||
```JavaScript | ||
ipfs.util.fsAdd(<dirpath>, { recursive: true }, (err, result) => { | ||
if (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of , let's put a real path there: ipfs.util.fsAdd('path/to/a/file', { recursive: true }, (err, result) => { |
||
throw err | ||
} | ||
console.log(result) | ||
}) | ||
``` | ||
|
||
`files` is an array of objects describing the files that were added, such as: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
[{ | ||
path: 'test-folder', | ||
hash: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6', | ||
size: 2278 | ||
}, | ||
// ... | ||
] | ||
``` | ||
|
||
#### Add a file from a URL to IPFS | ||
|
||
> `ipfs.util.urlAdd(url, callback)` | ||
|
||
```JavaScript | ||
ipfs.util.urlAdd('http://example.com/', (err, result) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log(result) | ||
}) | ||
|
||
``` | ||
|
||
#### Add a file from a stream to IPFS | ||
|
||
> `ipfs.util.streamAdd(stream, callback)` | ||
|
||
This is very similar to `ipfs.files.add({path:'', content: stream})`. It is like the reverse of cat | ||
|
||
```JavaScript | ||
ipfs.util.streamAdd(<readable-stream>, (err, result) => { | ||
if (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add an example how to write to the stream so that the example is explicit?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a readable-stream, you don't really write to it. |
||
throw err | ||
} | ||
console.log(result) | ||
}) | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the .streamAdd as a whole, how is it different from ipfs.files.add(stream, ...)? What does it take as an input to the stream? I think that should be described here, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing really, it is just 'backwards' "UX'ibility". ipfs.files.add does the same thing. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be too much bikeshedding, but I was thinking the naming of the functions. Instead of .fsAdd(), .streamAdd(), urlAdd() how about: I think switching the wording would make it a little from consistent and intuitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you got it :) |
||
### Callbacks and promises | ||
|
||
If you do not pass in a callback all API functions will return a `Promise`. For example: | ||
|
@@ -135,9 +193,11 @@ yet available you need to bring your own polyfill. | |
|
||
We run tests by executing `npm test` in a terminal window. This will run both Node.js and Browser tests, both in Chrome and PhantomJS. To ensure that the module conforms with the [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core) spec, we run the batch of tests provided by the interface module, which can be found [here](https://github.com/ipfs/interface-ipfs-core/tree/master/src). | ||
|
||
|
||
|
||
## Contribute | ||
|
||
The js-ipfs API is a work in progress. As such, there's a few things you can do right now to help out: | ||
The js-ipfs-api is a work in progress. As such, there's a few things you can do right now to help out: | ||
|
||
* **[Check out the existing issues](https://github.com/ipfs/js-ipfs-api/issues)**! | ||
* **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs. | ||
|
@@ -148,6 +208,10 @@ The js-ipfs API is a work in progress. As such, there's a few things you can do | |
|
||
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md) | ||
|
||
## Historical context | ||
|
||
This module started as a direct mapping from the go-ipfs cli to a JavaScript implementation, although this was useful and familiar to a lot of developers that were coming to IPFS for the first time, it also created some confusion on how to operate the core of IPFS and have access to the full capacity of the protocol. After much consideration, we decided to create `interface-ipfs-core` with the goal of standardizing the interface of a core implementation of IPFS, and keep the utility functions the IPFS community learned to use and love, such as reading files from disk and storing them directly to IPFS. | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
->remote
I'm guessing :)