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

Commit 8db5536

Browse files
authored
Merge pull request #305 from ipfs/ipfs-api/ng
next generation
2 parents c5e9d27 + c0e66cb commit 8db5536

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1505
-1221
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ before_install:
1111

1212
script:
1313
- npm run lint
14-
- npm test
14+
- npm run test:node
1515
- npm run coverage
1616

1717
addons:

API.md

-204
This file was deleted.

README.md

+72-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# js-ipfs-api
1+
ipfs-api
2+
========
23

34
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
45
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
@@ -9,7 +10,9 @@
910
[![Travis CI](https://travis-ci.org/ipfs/js-ipfs-api.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs-api)
1011
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-api.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-api)
1112

12-
> A client library for the IPFS HTTP API, implemented in JavaScript.
13+
> 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 remote IPFS node without having to change the code. In addition, this client library implements a set of utility functions.
14+
15+
![](https://github.com/ipfs/interface-ipfs-core/raw/master/img/badge.png)
1316

1417
## Table of Contents
1518

@@ -102,16 +105,71 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"http://exam
102105

103106
### API
104107

105-
> `WIP`
106-
107-
`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.
108+
> `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.
108109
109-
### Extra API methods
110+
### Utility functions
110111

111-
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.
112+
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`.
112113

113114
Complete documentation for these methods is coming with: https://github.com/ipfs/js-ipfs-api/pull/305
114115

116+
117+
#### Add files or entire directories from the FileSystem to IPFS
118+
119+
> `ipfs.util.addFromFs(path, option, callback)`
120+
121+
Reads a file from `path` on the filesystem and adds it to IPFS. If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
122+
123+
```JavaScript
124+
ipfs.util.addFromFs('path/to/a/file', { recursive: true }, (err, result) => {
125+
if (err) {
126+
throw err
127+
}
128+
console.log(result)
129+
})
130+
```
131+
132+
`result` is an array of objects describing the files that were added, such as:
133+
134+
```
135+
[{
136+
path: 'test-folder',
137+
hash: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6',
138+
size: 2278
139+
},
140+
// ...
141+
]
142+
```
143+
144+
#### Add a file from a URL to IPFS
145+
146+
> `ipfs.util.addFromURL(url, callback)`
147+
148+
```JavaScript
149+
ipfs.util.addFromURL('http://example.com/', (err, result) => {
150+
if (err) {
151+
throw err
152+
}
153+
console.log(result)
154+
})
155+
156+
```
157+
158+
#### Add a file from a stream to IPFS
159+
160+
> `ipfs.util.addFromStream(stream, callback)`
161+
162+
This is very similar to `ipfs.files.add({path:'', content: stream})`. It is like the reverse of cat
163+
164+
```JavaScript
165+
ipfs.util.addFromStream(<readable-stream>, (err, result) => {
166+
if (err) {
167+
throw err
168+
}
169+
console.log(result)
170+
})
171+
```
172+
115173
### Callbacks and promises
116174

117175
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.
135193

136194
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).
137195

196+
197+
138198
## Contribute
139199

140-
The js-ipfs API is a work in progress. As such, there's a few things you can do right now to help out:
200+
The js-ipfs-api is a work in progress. As such, there's a few things you can do right now to help out:
141201

142202
* **[Check out the existing issues](https://github.com/ipfs/js-ipfs-api/issues)**!
143203
* **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
148208

149209
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)
150210

211+
## Historical context
212+
213+
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.
214+
151215
## License
152216

153217
[MIT](LICENSE)

package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
{
22
"name": "ipfs-api",
33
"version": "6.0.3",
4-
"description": "A client library for the IPFS API",
4+
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
7+
"scripts": {
8+
"test": "node --max_old_space_size=4096 node_modules/.bin/gulp test:node",
9+
"test:node": "gulp test:node",
10+
"test:browser": "node --max_old_space_size=4096 node_modules/.bin/gulp test:browser",
11+
"lint": "aegir-lint",
12+
"build": "gulp build",
13+
"release": "node --max_old_space_size=4096 node_modules/.bin/gulp release",
14+
"release-minor": "node --max_old_space_size=4096 node_modules/.bin/gulp release --type minor",
15+
"release-major": "node --max_old_space_size=4096 node_modules/.bin/gulp release --type major",
16+
"coverage": "gulp coverage",
17+
"coverage-publish": "aegir-coverage publish"
18+
},
719
"dependencies": {
820
"async": "^2.0.1",
921
"babel-runtime": "^6.11.6",
@@ -20,6 +32,7 @@
2032
"ndjson": "^1.4.3",
2133
"promisify-es6": "^1.0.1",
2234
"qs": "^6.2.1",
35+
"tar-stream": "^1.5.2",
2336
"wreck": "^9.0.0"
2437
},
2538
"engines": {
@@ -30,32 +43,19 @@
3043
"url": "https://github.com/ipfs/js-ipfs-api"
3144
},
3245
"devDependencies": {
33-
"aegir": "^6.0.0",
46+
"aegir": "^6.0.1",
3447
"chai": "^3.5.0",
3548
"gulp": "^3.9.1",
3649
"hapi": "^14.1.0",
37-
"interface-ipfs-core": "^0.8.0",
50+
"interface-ipfs-core": "^0.13.0",
3851
"ipfsd-ctl": "^0.14.0",
39-
"passthrough-counter": "^1.0.0",
4052
"pre-commit": "^1.1.3",
4153
"socket.io": "^1.4.8",
4254
"socket.io-client": "^1.4.8",
4355
"stream-equal": "^0.1.8",
4456
"stream-http": "^2.3.1",
4557
"streamifier": "^0.1.1"
4658
},
47-
"scripts": {
48-
"test": "gulp test",
49-
"test:node": "gulp test:node",
50-
"test:browser": "gulp test:browser",
51-
"lint": "aegir-lint",
52-
"build": "gulp build",
53-
"release": "gulp release",
54-
"release-minor": "gulp release --type minor",
55-
"release-major": "gulp release --type major",
56-
"coverage": "gulp coverage",
57-
"coverage-publish": "aegir-coverage publish"
58-
},
5959
"pre-commit": [
6060
"lint",
6161
"test"

0 commit comments

Comments
 (0)