diff --git a/README.md b/README.md
index b50218380..a5fd30e6f 100644
--- a/README.md
+++ b/README.md
@@ -100,26 +100,27 @@ bitswap.unwant(key, (err) => {
})
```
-### In a web browser through Browserify
+### In a web browser
+
+**through Browserify**
Same as in Node.js, you just have to [browserify](http://browserify.org) the code before serving it. See the browserify repo for how to do that.
See the example in the [examples folder](/examples/bundle-browserify) to get a boilerplate.
-### In a web browser through webpack
+**through webpack**
See the example in the [examples folder](/examples/bundle-webpack) to get an idea on how to use js-ipfs-api with webpack.
-### In a web browser from CDN
+**from CDN**
-Instead of a local installation (and browserification) you may request a remote copy of IPFS API from [unpkg CDN](https://unpkg.com/).
+Instead of a local installation (and browserification) you may request a remote copy of IPFS API from [unpkg CDN](https://unpkg.com/).
To always request the latest version, use the following:
```html
-
```
@@ -141,13 +142,13 @@ crossorigin="anonymous">
CDN-based IPFS API provides the `IpfsApi` constructor as a method of the global `window` object. Example:
```js
-var ipfs = window.IpfsApi('localhost', '5001')
+const ipfs = window.IpfsApi('localhost', '5001')
```
If you omit the host and port, the API will parse `window.host`, and use this information. This also works, and can be useful if you want to write apps that can be run from multiple different gateways:
```js
-var ipfs = window.IpfsApi()
+const ipfs = window.IpfsApi()
```
### CORS
@@ -185,31 +186,34 @@ const ipfs = IpfsApi({
#### Files
-- [files](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md)
- - [`ipfs.files.add(data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesadd). Alias to `ipfs.add`.
- - [`ipfs.files.addPullStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesaddpullstream)
- - [`ipfs.files.addReadableStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesaddreadablestream)
- - [`ipfs.files.cat(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescat). Alias to `ipfs.cat`.
- - [`ipfs.files.catPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescatpullstream)
- - [`ipfs.files.catReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescatreadablestream)
- - [`ipfs.files.get(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesget). Alias to `ipfs.get`.
- - [`ipfs.files.getPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesgetpullstream)
- - [`ipfs.files.getReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesgetreadablestream)
+- [Regular Files API](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md)
+ - [`ipfs.add(data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add)
+ - [`ipfs.addPullStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addpullstream)
+ - [`ipfs.addReadableStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream)
+ - [`ipfs.addFromStream(stream, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromstream)
+ - [`ipfs.addFromFs(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromfs)
+ - [`ipfs.addFromUrl(url, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromurl)
+ - [`ipfs.cat(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#cat)
+ - [`ipfs.catPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#catpullstream)
+ - [`ipfs.catReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#catreadablestream)
+ - [`ipfs.get(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#get)
+ - [`ipfs.getPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#getpullstream)
+ - [`ipfs.getReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#getreadablestream)
- [`ipfs.ls(ipfsPath, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#ls)
- [`ipfs.lsPullStream(ipfsPath)`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#lspullstream)
- [`ipfs.lsReadableStream(ipfsPath)`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#lsreadablestream)
- - [MFS (mutable file system) specific](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#mutable-file-system)
- - [`ipfs.files.cp([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescp)
- - [`ipfs.files.flush([path], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesflush)
- - [`ipfs.files.ls([path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesls)
- - [`ipfs.files.mkdir(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmkdir)
- - [`ipfs.files.mv([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmv)
- - [`ipfs.files.read(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesread)
- - [`ipfs.files.readPullStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadpullstream)
- - [`ipfs.files.readReadableStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadreadablestream)
- - [`ipfs.files.rm(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesrm)
- - [`ipfs.files.stat(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesstat)
- - [`ipfs.files.write(path, content, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#fileswrite)
+- [MFS (mutable file system) specific](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#mutable-file-system)
+ - [`ipfs.files.cp([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescp)
+ - [`ipfs.files.flush([path], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesflush)
+ - [`ipfs.files.ls([path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesls)
+ - [`ipfs.files.mkdir(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmkdir)
+ - [`ipfs.files.mv([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmv)
+ - [`ipfs.files.read(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesread)
+ - [`ipfs.files.readPullStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadpullstream)
+ - [`ipfs.files.readReadableStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadreadablestream)
+ - [`ipfs.files.rm(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesrm)
+ - [`ipfs.files.stat(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesstat)
+ - [`ipfs.files.write(path, content, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#fileswrite)
- [block](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md)
- [`ipfs.block.get(cid, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockget)
@@ -359,69 +363,12 @@ A set of data types are exposed directly from the IPFS instance under `ipfs.type
- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb)
- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor)
-#### Utility functions
+#### Extra (util) 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. 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.addFromFs(path, option, callback)`
-
-Reads a file or folder from `path` on the filesystem and adds it to IPFS. Options:
-- **recursive**: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
- - **ignore**: To exclude fileglobs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
- - **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 }`.
-
-```JavaScript
-ipfs.util.addFromFs('path/to/a/folder', { recursive: true , ignore: ['subfolder/to/ignore/**']}, (err, result) => {
- if (err) { throw err }
- console.log(result)
-})
-```
-
-`result` is an array of objects describing the files that were added, such as:
-
-```js
-[
- {
- path: 'test-folder',
- hash: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6',
- size: 2278
- },
- // ...
-]
-```
-
-##### Add a file from a URL to IPFS
-
-> `ipfs.util.addFromURL(url, callback)`
-
-```JavaScript
-ipfs.util.addFromURL('http://example.com/', (err, result) => {
- if (err) {
- throw err
- }
- console.log(result)
-})
-```
-
-##### Add a file from a stream to IPFS
-
-> `ipfs.util.addFromStream(stream, callback)`
-
-This is very similar to `ipfs.files.add({path:'', content: stream})`. It is like the reverse of cat
-
-```JavaScript
-ipfs.util.addFromStream(, (err, result) => {
- if (err) {
- throw err
- }
- console.log(result)
-})
-```
-
##### Get endpoint configuration (host and port)
> `ipfs.util.getEndpointConfig()`
@@ -440,22 +387,6 @@ This contains an object with the crypto primitives
This contains an object with the is-ipfs utilities to help identifying IPFS resources
-### Callbacks and Promises
-
-If you do not pass in a callback all API functions will return a `Promise`. For example:
-
-```js
-ipfs.id()
- .then((id) => {
- console.log('my id is: ', id)
- })
- .catch((err) => {
- console.log('Fail: ', err)
- })
-```
-
-This relies on a global `Promise` object. If you are in an environment where that is not yet available you need to bring your own polyfill.
-
## Development
### Testing
@@ -466,10 +397,10 @@ We run tests by executing `npm test` in a terminal window. This will run both No
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.
-* **Add tests**. There can never be enough tests. Note that interface tests exist inside [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core/tree/master/js/src).
-* **Contribute to the [FAQ repository](https://github.com/ipfs/faq/issues)** with any questions you have about IPFS or any of the relevant technology. A good example would be asking, 'What is a merkledag tree?'. If you don't know a term, odds are, someone else doesn't either. Eventually, we should have a good understanding of where we need to improve communications and teaching together to make IPFS and IPN better.
+- **[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.
+- **Add tests**. There can never be enough tests. Note that interface tests exist inside [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core/tree/master/js/src).
+- **Contribute to the [FAQ repository](https://github.com/ipfs/faq/issues)** with any questions you have about IPFS or any of the relevant technology. A good example would be asking, 'What is a merkledag tree?'. If you don't know a term, odds are, someone else doesn't either. Eventually, we should have a good understanding of where we need to improve communications and teaching together to make IPFS and IPN better.
**Want to hack on IPFS?**
diff --git a/package.json b/package.json
index 3f2c56d6f..0fdb0f4a2 100644
--- a/package.json
+++ b/package.json
@@ -85,7 +85,7 @@
"eslint-plugin-react": "^7.11.1",
"go-ipfs-dep": "~0.4.18",
"gulp": "^3.9.1",
- "interface-ipfs-core": "~0.85.0",
+ "interface-ipfs-core": "~0.86.0",
"ipfsd-ctl": "~0.40.0",
"pull-stream": "^3.6.9",
"stream-equal": "^1.1.1"
diff --git a/src/add.js b/src/add.js
deleted file mode 100644
index 07915370e..000000000
--- a/src/add.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict'
-
-const moduleConfig = require('./utils/module-config')
-
-module.exports = (arg) => {
- const send = moduleConfig(arg)
-
- return require('./files/add')(send)
-}
diff --git a/src/cat.js b/src/cat.js
deleted file mode 100644
index 2d381efbc..000000000
--- a/src/cat.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict'
-
-const moduleConfig = require('./utils/module-config')
-
-module.exports = (arg) => {
- const send = moduleConfig(arg)
-
- return require('./files/cat')(send)
-}
diff --git a/src/files/cp.js b/src/files-mfs/cp.js
similarity index 100%
rename from src/files/cp.js
rename to src/files-mfs/cp.js
diff --git a/src/files/flush.js b/src/files-mfs/flush.js
similarity index 100%
rename from src/files/flush.js
rename to src/files-mfs/flush.js
diff --git a/src/files/index.js b/src/files-mfs/index.js
similarity index 54%
rename from src/files/index.js
rename to src/files-mfs/index.js
index 6bcbd722b..d4c6a8e7f 100644
--- a/src/files/index.js
+++ b/src/files-mfs/index.js
@@ -6,20 +6,9 @@ module.exports = (arg) => {
const send = moduleConfig(arg)
return {
- add: require('./add')(send),
- addReadableStream: require('./add-readable-stream')(send),
- addPullStream: require('./add-pull-stream')(send),
- cat: require('./cat')(send),
- catReadableStream: require('./cat-readable-stream')(send),
- catPullStream: require('./cat-pull-stream')(send),
- get: require('./get')(send),
- getReadableStream: require('./get-readable-stream')(send),
- getPullStream: require('./get-pull-stream')(send),
- flush: require('./flush')(send),
-
- // Specific to MFS (for now)
cp: require('./cp')(send),
mkdir: require('./mkdir')(send),
+ flush: require('./flush')(send),
stat: require('./stat')(send),
rm: require('./rm')(send),
ls: require('./ls')(send),
diff --git a/src/files/ls.js b/src/files-mfs/ls.js
similarity index 100%
rename from src/files/ls.js
rename to src/files-mfs/ls.js
diff --git a/src/files/mkdir.js b/src/files-mfs/mkdir.js
similarity index 100%
rename from src/files/mkdir.js
rename to src/files-mfs/mkdir.js
diff --git a/src/files/mv.js b/src/files-mfs/mv.js
similarity index 100%
rename from src/files/mv.js
rename to src/files-mfs/mv.js
diff --git a/src/files/read-pull-stream.js b/src/files-mfs/read-pull-stream.js
similarity index 100%
rename from src/files/read-pull-stream.js
rename to src/files-mfs/read-pull-stream.js
diff --git a/src/files/read-readable-stream.js b/src/files-mfs/read-readable-stream.js
similarity index 100%
rename from src/files/read-readable-stream.js
rename to src/files-mfs/read-readable-stream.js
diff --git a/src/files/read.js b/src/files-mfs/read.js
similarity index 100%
rename from src/files/read.js
rename to src/files-mfs/read.js
diff --git a/src/files/rm.js b/src/files-mfs/rm.js
similarity index 100%
rename from src/files/rm.js
rename to src/files-mfs/rm.js
diff --git a/src/files/stat.js b/src/files-mfs/stat.js
similarity index 100%
rename from src/files/stat.js
rename to src/files-mfs/stat.js
diff --git a/src/files/write.js b/src/files-mfs/write.js
similarity index 100%
rename from src/files/write.js
rename to src/files-mfs/write.js
diff --git a/src/util/fs-add.js b/src/files-regular/add-from-fs.js
similarity index 100%
rename from src/util/fs-add.js
rename to src/files-regular/add-from-fs.js
diff --git a/src/util/url-add.js b/src/files-regular/add-from-url.js
similarity index 100%
rename from src/util/url-add.js
rename to src/files-regular/add-from-url.js
diff --git a/src/files/add-pull-stream.js b/src/files-regular/add-pull-stream.js
similarity index 100%
rename from src/files/add-pull-stream.js
rename to src/files-regular/add-pull-stream.js
diff --git a/src/files/add-readable-stream.js b/src/files-regular/add-readable-stream.js
similarity index 100%
rename from src/files/add-readable-stream.js
rename to src/files-regular/add-readable-stream.js
diff --git a/src/files/add.js b/src/files-regular/add.js
similarity index 100%
rename from src/files/add.js
rename to src/files-regular/add.js
diff --git a/src/files/cat-pull-stream.js b/src/files-regular/cat-pull-stream.js
similarity index 100%
rename from src/files/cat-pull-stream.js
rename to src/files-regular/cat-pull-stream.js
diff --git a/src/files/cat-readable-stream.js b/src/files-regular/cat-readable-stream.js
similarity index 100%
rename from src/files/cat-readable-stream.js
rename to src/files-regular/cat-readable-stream.js
diff --git a/src/files/cat.js b/src/files-regular/cat.js
similarity index 100%
rename from src/files/cat.js
rename to src/files-regular/cat.js
diff --git a/src/files/get-pull-stream.js b/src/files-regular/get-pull-stream.js
similarity index 100%
rename from src/files/get-pull-stream.js
rename to src/files-regular/get-pull-stream.js
diff --git a/src/files/get-readable-stream.js b/src/files-regular/get-readable-stream.js
similarity index 100%
rename from src/files/get-readable-stream.js
rename to src/files-regular/get-readable-stream.js
diff --git a/src/files/get.js b/src/files-regular/get.js
similarity index 100%
rename from src/files/get.js
rename to src/files-regular/get.js
diff --git a/src/files-regular/index.js b/src/files-regular/index.js
new file mode 100644
index 000000000..98effdeb1
--- /dev/null
+++ b/src/files-regular/index.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const moduleConfig = require('../utils/module-config')
+
+module.exports = (arg) => {
+ const send = moduleConfig(arg)
+
+ return {
+ add: require('../files-regular/add')(send),
+ addReadableStream: require('../files-regular/add-readable-stream')(send),
+ addPullStream: require('../files-regular/add-pull-stream')(send),
+ addFromFs: require('../files-regular/add-from-fs')(send),
+ addFromUrl: require('../files-regular/add-from-url')(send),
+ addFromStream: require('../files-regular/add')(send),
+ cat: require('../files-regular/cat')(send),
+ catReadableStream: require('../files-regular/cat-readable-stream')(send),
+ catPullStream: require('../files-regular/cat-pull-stream')(send),
+ get: require('../files-regular/get')(send),
+ getReadableStream: require('../files-regular/get-readable-stream')(send),
+ getPullStream: require('../files-regular/get-pull-stream')(send),
+ ls: require('../files-regular/ls')(send),
+ lsReadableStream: require('../files-regular/ls-readable-stream')(send),
+ lsPullStream: require('../files-regular/ls-pull-stream')(send)
+ }
+}
diff --git a/src/ls-pull-stream.js b/src/files-regular/ls-pull-stream.js
similarity index 95%
rename from src/ls-pull-stream.js
rename to src/files-regular/ls-pull-stream.js
index eacb7e391..3430d60c2 100644
--- a/src/ls-pull-stream.js
+++ b/src/files-regular/ls-pull-stream.js
@@ -1,6 +1,6 @@
'use strict'
-const moduleConfig = require('./utils/module-config')
+const moduleConfig = require('../utils/module-config')
const pull = require('pull-stream')
const deferred = require('pull-defer')
diff --git a/src/ls-readable-stream.js b/src/files-regular/ls-readable-stream.js
similarity index 95%
rename from src/ls-readable-stream.js
rename to src/files-regular/ls-readable-stream.js
index 26005c5ee..9a15e1060 100644
--- a/src/ls-readable-stream.js
+++ b/src/files-regular/ls-readable-stream.js
@@ -1,6 +1,6 @@
'use strict'
-const moduleConfig = require('./utils/module-config')
+const moduleConfig = require('../utils/module-config')
const Stream = require('readable-stream')
module.exports = (arg) => {
diff --git a/src/ls.js b/src/files-regular/ls.js
similarity index 95%
rename from src/ls.js
rename to src/files-regular/ls.js
index 2ae92483c..772915e95 100644
--- a/src/ls.js
+++ b/src/files-regular/ls.js
@@ -1,7 +1,7 @@
'use strict'
const promisify = require('promisify-es6')
-const moduleConfig = require('./utils/module-config')
+const moduleConfig = require('../utils/module-config')
module.exports = (arg) => {
const send = moduleConfig(arg)
diff --git a/src/get.js b/src/get.js
deleted file mode 100644
index a7e04bce3..000000000
--- a/src/get.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict'
-
-const moduleConfig = require('./utils/module-config')
-
-module.exports = (arg) => {
- const send = moduleConfig(arg)
-
- return require('./files/get')(send)
-}
diff --git a/src/index.js b/src/index.js
index f0f73b782..323cab653 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,5 @@
'use strict'
+/* global self */
const multiaddr = require('multiaddr')
const loadCommands = require('./utils/load-commands')
diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js
index 55b4570ab..4d203defc 100644
--- a/src/utils/load-commands.js
+++ b/src/utils/load-commands.js
@@ -2,72 +2,75 @@
function requireCommands () {
const cmds = {
- // Files (not MFS)
- add: require('../files/add'),
- addReadableStream: require('../files/add-readable-stream'),
- addPullStream: require('../files/add-pull-stream'),
- cat: require('../files/cat'),
- catReadableStream: require('../files/cat-readable-stream'),
- catPullStream: require('../files/cat-pull-stream'),
- get: require('../files/get'),
- getReadableStream: require('../files/get-readable-stream'),
- getPullStream: require('../files/get-pull-stream'),
- ls: require('../ls'),
- lsReadableStream: require('../ls-readable-stream'),
- lsPullStream: require('../ls-pull-stream'),
+ // Files Regular (not MFS)
+ add: require('../files-regular/add'),
+ addReadableStream: require('../files-regular/add-readable-stream'),
+ addPullStream: require('../files-regular/add-pull-stream'),
+ addFromFs: require('../files-regular/add-from-fs'),
+ addFromURL: require('../files-regular/add-from-url'),
+ addFromStream: require('../files-regular/add'),
+ cat: require('../files-regular/cat'),
+ catReadableStream: require('../files-regular/cat-readable-stream'),
+ catPullStream: require('../files-regular/cat-pull-stream'),
+ get: require('../files-regular/get'),
+ getReadableStream: require('../files-regular/get-readable-stream'),
+ getPullStream: require('../files-regular/get-pull-stream'),
+ ls: require('../files-regular/ls'),
+ lsReadableStream: require('../files-regular/ls-readable-stream'),
+ lsPullStream: require('../files-regular/ls-pull-stream'),
- bitswap: require('../bitswap'),
+ // Block
block: require('../block'),
+ bitswap: require('../bitswap'),
+
+ // Graph
+ dag: require('../dag'),
+ object: require('../object'),
+ pin: require('../pin'),
+
+ // Network
bootstrap: require('../bootstrap'),
+ dht: require('../dht'),
+ name: require('../name'),
+ ping: require('../ping'),
+ pingReadableStream: require('../ping-readable-stream'),
+ pingPullStream: require('../ping-pull-stream'),
+ swarm: require('../swarm'),
+ pubsub: require('../pubsub'),
+ dns: require('../dns'),
+
+ // Miscellaneous
commands: require('../commands'),
config: require('../config'),
- dag: require('../dag'),
- dht: require('../dht'),
diag: require('../diag'),
id: require('../id'),
key: require('../key'),
log: require('../log'),
mount: require('../mount'),
- name: require('../name'),
- object: require('../object'),
- pin: require('../pin'),
- ping: require('../ping'),
- pingReadableStream: require('../ping-readable-stream'),
- pingPullStream: require('../ping-pull-stream'),
refs: require('../refs'),
repo: require('../repo'),
stop: require('../stop'),
stats: require('../stats'),
- swarm: require('../swarm'),
- pubsub: require('../pubsub'),
update: require('../update'),
version: require('../version'),
types: require('../types'),
- resolve: require('../resolve'),
- dns: require('../dns')
+ resolve: require('../resolve')
}
// shutdown is an alias for stop
cmds.shutdown = cmds.stop
- // TODO: crowding the 'files' namespace temporarily for interface-ipfs-core
- // compatibility, until 'files vs mfs' naming decision is resolved.
- cmds.files = function (send) {
- const files = require('../files')(send)
-
- return files
+ // Files MFS (Mutable Filesystem)
+ cmds.files = (send) => {
+ return require('../files-mfs')(send)
}
- cmds.util = function (send, config) {
- const util = {
- addFromFs: require('../util/fs-add')(send),
- addFromStream: require('../files/add')(send),
- addFromURL: require('../util/url-add')(send),
+ cmds.util = (send, config) => {
+ return {
getEndpointConfig: require('../util/get-endpoint-config')(config),
crypto: require('libp2p-crypto'),
isIPFS: require('is-ipfs')
}
- return util
}
return cmds
diff --git a/test/files.spec.js b/test/files-mfs.spec.js
similarity index 82%
rename from test/files.spec.js
rename to test/files-mfs.spec.js
index 05477c41b..2929bea16 100644
--- a/test/files.spec.js
+++ b/test/files-mfs.spec.js
@@ -51,8 +51,8 @@ describe('.files (the MFS API part)', function () {
ipfsd.stop(done)
})
- it('add file for testing', (done) => {
- ipfs.files.add(testfile, (err, res) => {
+ it('.add file for testing', (done) => {
+ ipfs.add(testfile, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -62,13 +62,13 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with Buffer module', (done) => {
+ it('.add with Buffer module', (done) => {
let Buffer = require('buffer').Buffer
let expectedBufferMultihash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX'
let file = Buffer.from('hello')
- ipfs.files.add(file, (err, res) => {
+ ipfs.add(file, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -78,11 +78,11 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with empty path and buffer content', (done) => {
+ it('.add with empty path and buffer content', (done) => {
const expectedHash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX'
const content = Buffer.from('hello')
- ipfs.files.add([{ path: '', content }], (err, res) => {
+ ipfs.add([{ path: '', content }], (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -92,11 +92,11 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with cid-version=1 and raw-leaves=false', (done) => {
+ it('.add with cid-version=1 and raw-leaves=false', (done) => {
const expectedCid = 'zdj7Wh9x6gXdg4UAqhRYnjBTw9eJF7hvzUU4HjpnZXHYQz9jK'
const options = { 'cid-version': 1, 'raw-leaves': false }
- ipfs.files.add(testfile, options, (err, res) => {
+ ipfs.add(testfile, options, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -106,11 +106,11 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with only-hash=true', function () {
+ it('.add with only-hash=true', function () {
this.slow(10 * 1000)
const content = String(Math.random() + Date.now())
- return ipfs.files.add(Buffer.from(content), { onlyHash: true })
+ return ipfs.add(Buffer.from(content), { onlyHash: true })
.then(files => {
expect(files).to.have.length(1)
@@ -119,8 +119,8 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with options', (done) => {
- ipfs.files.add(testfile, { pin: false }, (err, res) => {
+ it('.add with options', (done) => {
+ ipfs.add(testfile, { pin: false }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -130,13 +130,13 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add pins by default', (done) => {
+ it('.add pins by default', (done) => {
const newContent = Buffer.from(String(Math.random()))
ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
const initialPinCount = pins.length
- ipfs.files.add(newContent, (err, res) => {
+ ipfs.add(newContent, (err, res) => {
expect(err).to.not.exist()
ipfs.pin.ls((err, pins) => {
@@ -148,13 +148,13 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add with pin=false', (done) => {
+ it('.add with pin=false', (done) => {
const newContent = Buffer.from(String(Math.random()))
ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
const initialPinCount = pins.length
- ipfs.files.add(newContent, { pin: false }, (err, res) => {
+ ipfs.add(newContent, { pin: false }, (err, res) => {
expect(err).to.not.exist()
ipfs.pin.ls((err, pins) => {
@@ -167,7 +167,7 @@ describe('.files (the MFS API part)', function () {
})
HASH_ALGS.forEach((name) => {
- it(`files.add with hash=${name} and raw-leaves=false`, (done) => {
+ it(`.add with hash=${name} and raw-leaves=false`, (done) => {
const content = String(Math.random() + Date.now())
const file = {
path: content + '.txt',
@@ -175,7 +175,7 @@ describe('.files (the MFS API part)', function () {
}
const options = { hash: name, 'raw-leaves': false }
- ipfs.files.add([file], options, (err, res) => {
+ ipfs.add([file], options, (err, res) => {
if (err) return done(err)
expect(res).to.have.length(1)
const cid = new CID(res[0].hash)
@@ -185,7 +185,7 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add file with progress option', (done) => {
+ it('.add file with progress option', (done) => {
let progress
let progressCount = 0
@@ -194,7 +194,7 @@ describe('.files (the MFS API part)', function () {
progress = p
}
- ipfs.files.add(testfile, { progress: progressHandler }, (err, res) => {
+ ipfs.add(testfile, { progress: progressHandler }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -205,7 +205,7 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add big file with progress option', (done) => {
+ it('.add big file with progress option', (done) => {
let progress = 0
let progressCount = 0
@@ -215,7 +215,7 @@ describe('.files (the MFS API part)', function () {
}
// TODO: needs to be using a big file
- ipfs.files.add(testfile, { progress: progressHandler }, (err, res) => {
+ ipfs.add(testfile, { progress: progressHandler }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -226,7 +226,7 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add directory with progress option', (done) => {
+ it('.add directory with progress option', (done) => {
let progress = 0
let progressCount = 0
@@ -236,7 +236,7 @@ describe('.files (the MFS API part)', function () {
}
// TODO: needs to be using a directory
- ipfs.files.add(testfile, { progress: progressHandler }, (err, res) => {
+ ipfs.add(testfile, { progress: progressHandler }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -247,8 +247,8 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.add without progress options', (done) => {
- ipfs.files.add(testfile, (err, res) => {
+ it('.add without progress options', (done) => {
+ ipfs.add(testfile, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
@@ -257,7 +257,7 @@ describe('.files (the MFS API part)', function () {
})
HASH_ALGS.forEach((name) => {
- it(`files.add with hash=${name} and raw-leaves=false`, (done) => {
+ it(`.add with hash=${name} and raw-leaves=false`, (done) => {
const content = String(Math.random() + Date.now())
const file = {
path: content + '.txt',
@@ -265,8 +265,9 @@ describe('.files (the MFS API part)', function () {
}
const options = { hash: name, 'raw-leaves': false }
- ipfs.files.add([file], options, (err, res) => {
- if (err) return done(err)
+ ipfs.add([file], options, (err, res) => {
+ expect(err).to.not.exist()
+
expect(res).to.have.length(1)
const cid = new CID(res[0].hash)
expect(mh.decode(cid.multihash).name).to.equal(name)
@@ -275,14 +276,15 @@ describe('.files (the MFS API part)', function () {
})
})
- it('files.addPullStream with object chunks and pull stream content', (done) => {
+ it('.addPullStream with object chunks and pull stream content', (done) => {
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
pull(
pull.values([{ content: pull.values([Buffer.from('test')]) }]),
- ipfs.files.addPullStream(),
+ ipfs.addPullStream(),
pull.collect((err, res) => {
- if (err) return done(err)
+ expect(err).to.not.exist()
+
expect(res).to.have.length(1)
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
done()
@@ -290,34 +292,35 @@ describe('.files (the MFS API part)', function () {
)
})
- it('files.add with pull stream (callback)', (done) => {
+ it('.add with pull stream (callback)', (done) => {
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
- ipfs.files.add(pull.values([Buffer.from('test')]), (err, res) => {
- if (err) return done(err)
+ ipfs.add(pull.values([Buffer.from('test')]), (err, res) => {
+ expect(err).to.not.exist()
+
expect(res).to.have.length(1)
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
done()
})
})
- it('files.add with pull stream (promise)', () => {
+ it('.add with pull stream (promise)', () => {
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
- return ipfs.files.add(pull.values([Buffer.from('test')]))
+ return ipfs.add(pull.values([Buffer.from('test')]))
.then((res) => {
expect(res).to.have.length(1)
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
})
})
- it('files.add with array of objects with pull stream content', () => {
+ it('.add with array of objects with pull stream content', () => {
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
- return ipfs.files.add([{ content: pull.values([Buffer.from('test')]) }])
+ return ipfs.add([{ content: pull.values([Buffer.from('test')]) }])
.then((res) => {
expect(res).to.have.length(1)
- expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
+ expect(res[0]).to.eql({ path: expectedCid, hash: expectedCid, size: 12 })
})
})
@@ -407,7 +410,7 @@ describe('.files (the MFS API part)', function () {
it('files.write', (done) => {
ipfs.files
- .write('/test-folder/test-file-2.txt', Buffer.from('hello world'), {create: true}, (err) => {
+ .write('/test-folder/test-file-2.txt', Buffer.from('hello world'), { create: true }, (err) => {
expect(err).to.not.exist()
ipfs.files.read('/test-folder/test-file-2.txt', (err, buf) => {
@@ -483,6 +486,6 @@ describe('.files (the MFS API part)', function () {
})
it('files.rm', (done) => {
- ipfs.files.rm('/test-folder', {recursive: true}, done)
+ ipfs.files.rm('/test-folder', { recursive: true }, done)
})
})
diff --git a/test/fixtures/weird name folder [v0]/add b/test/fixtures/weird name folder [v0]/add
deleted file mode 100644
index ce7fb7cc8..000000000
--- a/test/fixtures/weird name folder [v0]/add
+++ /dev/null
@@ -1,22 +0,0 @@
-'use strict'
-
-const ipfs = require('../src')('localhost', 5001)
-
-const f1 = 'Hello'
-const f2 = 'World'
-
-ipfs.add([new Buffer(f1), new Buffer(f2)], function (err, res) {
- if (err || !res) return console.log(err)
-
- for (let i = 0; i < res.length; i++) {
- console.log(res[i])
- }
-})
-
-ipfs.add(['./files/hello.txt', './files/ipfs.txt'], function (err, res) {
- if (err || !res) return console.log(err)
-
- for (let i = 0; i < res.length; i++) {
- console.log(res[i])
- }
-})
diff --git a/test/fixtures/weird name folder [v0]/cat b/test/fixtures/weird name folder [v0]/cat
deleted file mode 100644
index 9bfc46638..000000000
--- a/test/fixtures/weird name folder [v0]/cat
+++ /dev/null
@@ -1,18 +0,0 @@
-'use strict'
-
-const ipfs = require('../src')('localhost', 5001)
-
-const hash = [
- 'QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w',
- 'QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu'
-]
-
-ipfs.cat(hash, function (err, res) {
- if (err || !res) return console.log(err)
-
- if (res.readable) {
- res.pipe(process.stdout)
- } else {
- console.log(res)
- }
-})
diff --git a/test/fixtures/weird name folder [v0]/files/hello.txt b/test/fixtures/weird name folder [v0]/files/hello.txt
deleted file mode 100644
index e965047ad..000000000
--- a/test/fixtures/weird name folder [v0]/files/hello.txt
+++ /dev/null
@@ -1 +0,0 @@
-Hello
diff --git a/test/fixtures/weird name folder [v0]/files/ipfs.txt b/test/fixtures/weird name folder [v0]/files/ipfs.txt
deleted file mode 100644
index 95a311652..000000000
--- a/test/fixtures/weird name folder [v0]/files/ipfs.txt
+++ /dev/null
@@ -1 +0,0 @@
-IPFS
diff --git a/test/fixtures/weird name folder [v0]/hello-link b/test/fixtures/weird name folder [v0]/hello-link
deleted file mode 120000
index 50b07e9e7..000000000
--- a/test/fixtures/weird name folder [v0]/hello-link
+++ /dev/null
@@ -1 +0,0 @@
-files/hello.txt
\ No newline at end of file
diff --git a/test/fixtures/weird name folder [v0]/ipfs-add b/test/fixtures/weird name folder [v0]/ipfs-add
deleted file mode 100755
index 962aa11fe..000000000
--- a/test/fixtures/weird name folder [v0]/ipfs-add
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env node
-
-'use strict'
-
-const ipfs = require('../src')('localhost', 5001)
-const files = process.argv.slice(2)
-
-ipfs.add(files, {recursive: true}, function (err, res) {
- if (err || !res) return console.log(err)
-
- for (let i = 0; i < res.length; i++) {
- console.log('added', res[i].Hash, res[i].Name)
- }
-})
diff --git a/test/fixtures/weird name folder [v0]/ls b/test/fixtures/weird name folder [v0]/ls
deleted file mode 100644
index c810fbead..000000000
--- a/test/fixtures/weird name folder [v0]/ls
+++ /dev/null
@@ -1,18 +0,0 @@
-'use strict'
-
-const ipfs = require('../src')('localhost', 5001)
-
-const hash = ['QmdbHK6gMiecyjjSoPnfJg6iKMF7v6E2NkoBgGpmyCoevh']
-
-ipfs.ls(hash, function (err, res) {
- if (err || !res) return console.log(err)
-
- res.Objects.forEach(function (node) {
- console.log(node.Hash)
-
- console.log('Links [%d]', node.Links.length)
- node.Links.forEach(function (link, i) {
- console.log('[%d]', i, link)
- })
- })
-})
diff --git a/test/fixtures/weird name folder [v0]/version b/test/fixtures/weird name folder [v0]/version
deleted file mode 100644
index a792af011..000000000
--- a/test/fixtures/weird name folder [v0]/version
+++ /dev/null
@@ -1,8 +0,0 @@
-'use strict'
-
-const ipfs = require('../src')('localhost', 5001)
-
-ipfs.commands(function (err, res) {
- if (err) throw err
- console.log(res)
-})
diff --git a/test/get.spec.js b/test/get.spec.js
index 91d16f3fe..29987bce1 100644
--- a/test/get.spec.js
+++ b/test/get.spec.js
@@ -37,12 +37,12 @@ describe('.get (specific go-ipfs features)', function () {
ipfs = IPFSApi(_ipfsd.apiAddr)
cb()
}),
- (cb) => ipfs.files.add(smallFile.data, cb)
+ (cb) => ipfs.add(smallFile.data, cb)
], done)
})
after((done) => {
- if (!ipfsd) return done()
+ if (!ipfsd) { return done() }
ipfsd.stop(done)
})
@@ -83,9 +83,7 @@ describe('.get (specific go-ipfs features)', function () {
})
it('add path containing "+"s (for testing get)', (done) => {
- if (!isNode) {
- return done()
- }
+ if (!isNode) { return done() }
const filename = 'ti,c64x+mega++mod-pic.txt'
const subdir = 'tmp/c++files'
@@ -101,9 +99,7 @@ describe('.get (specific go-ipfs features)', function () {
})
it('get path containing "+"s', (done) => {
- if (!isNode) {
- return done()
- }
+ if (!isNode) { return done() }
const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
let count = 0
diff --git a/test/interface.spec.js b/test/interface.spec.js
index f91b8b9d5..d3be72bae 100644
--- a/test/interface.spec.js
+++ b/test/interface.spec.js
@@ -7,7 +7,7 @@ const CommonFactory = require('./utils/interface-common-factory')
const IPFSApi = require('../src')
const isWindows = process.platform && process.platform === 'win32'
-describe('interface-ipfs-core tests', () => {
+describe.only('interface-ipfs-core tests', () => {
const defaultCommonFactory = CommonFactory.create()
tests.bitswap(defaultCommonFactory, {
@@ -91,9 +91,9 @@ describe('interface-ipfs-core tests', () => {
]
})
- tests.files(defaultCommonFactory, {
+ tests.filesRegular(defaultCommonFactory, {
skip: [
- // files.add
+ // .add
isNode ? null : {
name: 'should add a nested directory as array of tupples',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
@@ -102,17 +102,32 @@ describe('interface-ipfs-core tests', () => {
name: 'should add a nested directory as array of tupples with progress',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
- // files.addPullStream
+ // .addPullStream
isNode ? null : {
name: 'should add pull stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
- // files.addReadableStream
+ // .addReadableStream
isNode ? null : {
name: 'should add readable stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
- // files.catPullStream
+ // .addFromStream
+ isNode ? null : {
+ name: 'addFromStream',
+ reason: 'Not designed to run in the browser'
+ },
+ // .addFromFs
+ isNode ? null : {
+ name: 'addFromFs',
+ reason: 'Not designed to run in the browser'
+ },
+ // .addFromUrl
+ isNode ? null : {
+ name: 'addFromUrl',
+ reason: 'Not designed to run in the browser'
+ },
+ // .catPullStream
{
name: 'should export a chunk of a file',
reason: 'TODO not implemented in go-ipfs yet'
@@ -125,19 +140,31 @@ describe('interface-ipfs-core tests', () => {
name: 'should export a chunk of a file in a Readable Stream',
reason: 'TODO not implemented in go-ipfs yet'
},
- // files.get
+ // .get
isNode ? null : {
name: 'should get a directory',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
- // files.write
- {
- name: 'should write to deeply nested non existent file with create and parents flags',
- reason: 'TODO remove when 0.4.18 is released https://github.com/ipfs/go-ipfs/pull/5359'
+ // .ls
+ isNode ? null : {
+ name: 'should ls with a base58 encoded CID',
+ reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
+ },
+ // .lsPullStream
+ isNode ? null : {
+ name: 'should pull stream ls with a base58 encoded CID',
+ reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
+ },
+ // .lsReadableStream
+ isNode ? null : {
+ name: 'should readable stream ls with a base58 encoded CID',
+ reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
}
]
})
+ tests.filesMFS(defaultCommonFactory)
+
tests.key(defaultCommonFactory, {
skip: [
// key.export
@@ -153,26 +180,6 @@ describe('interface-ipfs-core tests', () => {
]
})
- tests.ls(defaultCommonFactory, {
- skip: [
- // lsPullStream
- isNode ? null : {
- name: 'should pull stream ls with a base58 encoded CID',
- reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
- },
- // lsReadableStream
- isNode ? null : {
- name: 'should readable stream ls with a base58 encoded CID',
- reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
- },
- // ls
- isNode ? null : {
- name: 'should ls with a base58 encoded CID',
- reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
- }
- ]
- })
-
tests.miscellaneous(defaultCommonFactory, {
skip: [
// stop
diff --git a/test/name.spec.js b/test/name.spec.js
index 3e5d0402b..58de812fe 100644
--- a/test/name.spec.js
+++ b/test/name.spec.js
@@ -53,7 +53,7 @@ describe('.name', () => {
})
},
(cb) => {
- ipfs.files.add(testfile, (err, res) => {
+ ipfs.add(testfile, (err, res) => {
expect(err).to.not.exist()
testFileCid = res[0].hash
cb()
diff --git a/test/ping.spec.js b/test/ping.spec.js
index 06848ee78..184f99b8d 100644
--- a/test/ping.spec.js
+++ b/test/ping.spec.js
@@ -21,7 +21,7 @@ function isPong (pingResponse) {
}
describe('.ping', function () {
- this.timeout(10 * 1000)
+ this.timeout(20 * 1000)
let ipfs
let ipfsd
@@ -131,7 +131,7 @@ describe('.ping', function () {
it('.ping fails with count & n', function (done) {
this.timeout(20 * 1000)
- ipfs.ping(otherId, {count: 2, n: 2}, (err, res) => {
+ ipfs.ping(otherId, { count: 2, n: 2 }, (err, res) => {
expect(err).to.exist()
done()
})
@@ -189,7 +189,7 @@ describe('.ping', function () {
it('message conversion fails if invalid message is received', () => {
const messageConverter = new PingMessageStream()
expect(() => {
- messageConverter.write({some: 'InvalidMessage'})
+ messageConverter.write({ some: 'InvalidMessage' })
}).to.throw('Invalid ping message received')
})
})
diff --git a/test/refs.spec.js b/test/refs.spec.js
index 7ce245455..4f6cc2864 100644
--- a/test/refs.spec.js
+++ b/test/refs.spec.js
@@ -39,7 +39,7 @@ describe('.refs', function () {
(_ipfsd, cb) => {
ipfsd = _ipfsd
ipfs = IPFSApi(_ipfsd.apiAddr)
- ipfs.util.addFromFs(filesPath, { recursive: true }, cb)
+ ipfs.addFromFs(filesPath, { recursive: true }, cb)
},
(hashes, cb) => {
folder = hashes[hashes.length - 1].hash
diff --git a/test/request-api.spec.js b/test/request-api.spec.js
index 63a2dce24..8f43a3fae 100644
--- a/test/request-api.spec.js
+++ b/test/request-api.spec.js
@@ -54,7 +54,7 @@ describe('trailer headers', () => {
server.listen(6001, () => {
const ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/6001')
/* eslint-disable */
- ipfs.files.add(Buffer.from('Hello there!'), (err, res) => {
+ ipfs.add(Buffer.from('Hello there!'), (err, res) => {
// TODO: error's are not being correctly
// propagated with Trailer headers yet
// expect(err).to.exist()
diff --git a/test/sub-modules.spec.js b/test/sub-modules.spec.js
index 1921b0228..0401eccfe 100644
--- a/test/sub-modules.spec.js
+++ b/test/sub-modules.spec.js
@@ -165,26 +165,37 @@ describe('submodules', () => {
expect(pubsub.peers).to.be.a('function')
})
- it('files', () => {
- const files = require('../src/files')(config)
-
- expect(files.add).to.be.a('function')
- expect(files.addReadableStream).to.be.a('function')
- expect(files.addPullStream).to.be.a('function')
- expect(files.get).to.be.a('function')
- expect(files.getReadableStream).to.be.a('function')
- expect(files.getPullStream).to.be.a('function')
- expect(files.cat).to.be.a('function')
- expect(files.catReadableStream).to.be.a('function')
- expect(files.catPullStream).to.be.a('function')
- expect(files.cp).to.be.a('function')
- expect(files.ls).to.be.a('function')
- expect(files.mkdir).to.be.a('function')
- expect(files.stat).to.be.a('function')
- expect(files.rm).to.be.a('function')
- expect(files.read).to.be.a('function')
- expect(files.write).to.be.a('function')
- expect(files.mv).to.be.a('function')
+ it('files regular API', () => {
+ const filesRegular = require('../src/files-regular')(config)
+
+ expect(filesRegular.add).to.be.a('function')
+ expect(filesRegular.addReadableStream).to.be.a('function')
+ expect(filesRegular.addPullStream).to.be.a('function')
+ expect(filesRegular.addFromStream).to.be.a('function')
+ expect(filesRegular.addFromFs).to.be.a('function')
+ expect(filesRegular.addFromUrl).to.be.a('function')
+ expect(filesRegular.get).to.be.a('function')
+ expect(filesRegular.getReadableStream).to.be.a('function')
+ expect(filesRegular.getPullStream).to.be.a('function')
+ expect(filesRegular.cat).to.be.a('function')
+ expect(filesRegular.catReadableStream).to.be.a('function')
+ expect(filesRegular.catPullStream).to.be.a('function')
+ expect(filesRegular.ls).to.be.a('function')
+ expect(filesRegular.lsReadableStream).to.be.a('function')
+ expect(filesRegular.lsPullStream).to.be.a('function')
+ })
+
+ it('files MFS API', () => {
+ const filesMFS = require('../src/files-mfs')(config)
+
+ expect(filesMFS.cp).to.be.a('function')
+ expect(filesMFS.ls).to.be.a('function')
+ expect(filesMFS.mkdir).to.be.a('function')
+ expect(filesMFS.stat).to.be.a('function')
+ expect(filesMFS.rm).to.be.a('function')
+ expect(filesMFS.read).to.be.a('function')
+ expect(filesMFS.write).to.be.a('function')
+ expect(filesMFS.mv).to.be.a('function')
})
it('commands', () => {
@@ -193,52 +204,16 @@ describe('submodules', () => {
expect(commands).to.be.a('function')
})
- it('ls', () => {
- const ls = require('../src/ls')(config)
-
- expect(ls).to.be.a('function')
- })
-
it('mount', () => {
const mount = require('../src/mount')(config)
expect(mount).to.be.a('function')
})
- it('fs-add', () => {
- const fsAdd = require('../src/util/fs-add')(config)
-
- expect(fsAdd).to.be.a('function')
- })
-
- it('url-add', () => {
- const urlAdd = require('../src/util/url-add')(config)
-
- expect(urlAdd).to.be.a('function')
- })
-
it('refs', () => {
const refs = require('../src/refs')(config)
expect(refs).to.be.a('function')
expect(refs.local).to.be.a('function')
})
-
- it('add', () => {
- const add = require('../src/add')(config)
-
- expect(add).to.be.a('function')
- })
-
- it('get', () => {
- const get = require('../src/get')(config)
-
- expect(get).to.be.a('function')
- })
-
- it('cat', () => {
- const cat = require('../src/cat')(config)
-
- expect(cat).to.be.a('function')
- })
})
diff --git a/test/util.spec.js b/test/util.spec.js
index 6109e5cc9..559f9abd7 100644
--- a/test/util.spec.js
+++ b/test/util.spec.js
@@ -7,18 +7,9 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
-const path = require('path')
-const fs = require('fs')
-const os = require('os')
-const http = require('http')
-const https = require('https')
-const each = require('async/each')
-const waterfall = require('async/waterfall')
-const parallel = require('async/parallel')
const IPFSApi = require('../src')
const f = require('./utils/factory')
-const expectTimeout = require('./utils/expect-timeout')
describe('.util', () => {
if (!isNode) { return }
@@ -43,345 +34,6 @@ describe('.util', () => {
ipfsd.stop(done)
})
- it('.streamAdd', (done) => {
- const tfpath = path.join(__dirname, '/fixtures/testfile.txt')
- const rs = fs.createReadStream(tfpath)
- rs.path = '' // clean the path for testing purposes
-
- ipfs.util.addFromStream(rs, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.equal(1)
- done()
- })
- })
-
- describe('.fsAdd should add', () => {
- it('a directory', (done) => {
- const filesPath = path.join(__dirname, '/fixtures/test-folder')
- ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.be.above(8)
- done()
- })
- })
-
- it('a directory with an odd name', (done) => {
- const filesPath = path.join(__dirname, '/fixtures/weird name folder [v0]')
- ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.be.above(8)
- done()
- })
- })
-
- it('add and ignore a directory', (done) => {
- const filesPath = path.join(__dirname, '/fixtures/test-folder')
- ipfs.util.addFromFs(filesPath, { recursive: true, ignore: ['files/**'] }, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.be.below(9)
- done()
- })
- })
-
- it('a file', (done) => {
- const filePath = path.join(__dirname, '/fixtures/testfile.txt')
- ipfs.util.addFromFs(filePath, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.be.equal(1)
- expect(result[0].path).to.be.equal('testfile.txt')
- done()
- })
- })
-
- it('a hidden file in a directory', (done) => {
- const filesPath = path.join(__dirname, '/fixtures/test-folder')
- ipfs.util.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => {
- expect(err).to.not.exist()
- expect(result.length).to.be.above(10)
- expect(result.map(object => object.path)).to.include('test-folder/.hiddenTest.txt')
- expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt')
- done()
- })
- })
-
- it('with only-hash=true', function () {
- this.slow(10 * 1000)
- const content = String(Math.random() + Date.now())
- const filepath = path.join(os.tmpdir(), `${content}.txt`)
- fs.writeFileSync(filepath, content)
-
- return ipfs.util.addFromFs(filepath, { onlyHash: true })
- .then(out => {
- fs.unlinkSync(filepath)
- return expectTimeout(ipfs.object.get(out[0].hash), 4000)
- })
- })
- })
-
- describe('.urlAdd', () => {
- let testServers = []
-
- const sslOpts = {
- key: fs.readFileSync(path.join(__dirname, 'fixtures', 'ssl', 'privkey.pem')),
- cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'ssl', 'cert.pem'))
- }
-
- const startTestServer = (handler, opts, cb) => {
- if (typeof opts === 'function') {
- cb = opts
- opts = {}
- }
-
- const server = opts.secure
- ? https.createServer(sslOpts, handler)
- : http.createServer(handler)
-
- server.listen((err) => {
- if (err) return cb(err)
- testServers.push(server)
- cb(null, server)
- })
- }
-
- beforeEach(() => {
- // Instructs node to not reject our snake oil SSL certificate when it
- // can't verify the certificate authority
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
- })
-
- afterEach((done) => {
- // Reinstate unauthorised SSL cert rejection
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1
-
- each(testServers, (server, cb) => server.close(cb), (err) => {
- testServers = []
- done(err)
- })
- })
-
- it('http', (done) => {
- const data = Buffer.from(`TEST${Date.now()}`)
-
- parallel({
- server: (cb) => {
- const handler = (req, res) => {
- res.write(data)
- res.end()
- }
- startTestServer(handler, cb)
- },
- expectedResult: (cb) => ipfs.add(data, cb)
- }, (err, taskResult) => {
- expect(err).to.not.exist()
- const { server, expectedResult } = taskResult
-
- const url = `http://127.0.0.1:${server.address().port}/`
- ipfs.util.addFromURL(url, (err, result) => {
- expect(err).to.not.exist()
- expect(result).to.deep.equal(expectedResult)
- done()
- })
- })
- })
-
- it('https', (done) => {
- const data = Buffer.from(`TEST${Date.now()}`)
-
- parallel({
- server: (cb) => {
- const handler = (req, res) => {
- res.write(data)
- res.end()
- }
- startTestServer(handler, { secure: true }, cb)
- },
- expectedResult: (cb) => ipfs.add(data, cb)
- }, (err, taskResult) => {
- expect(err).to.not.exist()
- const { server, expectedResult } = taskResult
-
- const url = `https://127.0.0.1:${server.address().port}/`
- ipfs.util.addFromURL(url, (err, result) => {
- expect(err).to.not.exist()
- expect(result).to.deep.equal(expectedResult)
- done()
- })
- })
- })
-
- it('http with redirection', (done) => {
- const data = Buffer.from(`TEST${Date.now()}`)
-
- waterfall([
- (cb) => {
- const handler = (req, res) => {
- res.write(data)
- res.end()
- }
- startTestServer(handler, cb)
- },
- (serverA, cb) => {
- const url = `http://127.0.0.1:${serverA.address().port}`
- const handler = (req, res) => {
- res.statusCode = 302
- res.setHeader('Location', url)
- res.end()
- }
- startTestServer(handler, (err, serverB) => {
- if (err) return cb(err)
- cb(null, { a: serverA, b: serverB })
- })
- }
- ], (err, servers) => {
- expect(err).to.not.exist()
-
- ipfs.add(data, (err, res) => {
- expect(err).to.not.exist()
-
- const expectedHash = res[0].hash
- const url = `http://127.0.0.1:${servers.b.address().port}`
-
- ipfs.util.addFromURL(url, (err, result) => {
- expect(err).to.not.exist()
- expect(result[0].hash).to.equal(expectedHash)
- done()
- })
- })
- })
- })
-
- it('https with redirection', (done) => {
- const data = Buffer.from(`TEST${Date.now()}`)
-
- waterfall([
- (cb) => {
- const handler = (req, res) => {
- res.write(data)
- res.end()
- }
- startTestServer(handler, { secure: true }, cb)
- },
- (serverA, cb) => {
- const url = `https://127.0.0.1:${serverA.address().port}`
- const handler = (req, res) => {
- res.statusCode = 302
- res.setHeader('Location', url)
- res.end()
- }
- startTestServer(handler, { secure: true }, (err, serverB) => {
- if (err) return cb(err)
- cb(null, { a: serverA, b: serverB })
- })
- }
- ], (err, servers) => {
- expect(err).to.not.exist()
-
- ipfs.add(data, (err, res) => {
- expect(err).to.not.exist()
-
- const expectedHash = res[0].hash
- const url = `https://127.0.0.1:${servers.b.address().port}`
-
- ipfs.util.addFromURL(url, (err, result) => {
- expect(err).to.not.exist()
- expect(result[0].hash).to.equal(expectedHash)
- done()
- })
- })
- })
- })
-
- it('with only-hash=true', (done) => {
- const handler = (req, res) => {
- res.write(`TEST${Date.now()}`)
- res.end()
- }
-
- startTestServer(handler, (err, server) => {
- expect(err).to.not.exist()
-
- const url = `http://127.0.0.1:${server.address().port}/`
-
- ipfs.util.addFromURL(url, { onlyHash: true }, (err, res) => {
- expect(err).to.not.exist()
-
- // A successful object.get for this size data took my laptop ~14ms
- let didTimeout = false
- const timeoutId = setTimeout(() => {
- didTimeout = true
- done()
- }, 500)
-
- ipfs.object.get(res[0].hash, () => {
- clearTimeout(timeoutId)
- if (didTimeout) return
- expect(new Error('did not timeout')).to.not.exist()
- })
- })
- })
- })
-
- it('with wrap-with-directory=true', (done) => {
- const filename = `TEST${Date.now()}.txt`
- const data = Buffer.from(`TEST${Date.now()}`)
-
- parallel({
- server: (cb) => startTestServer((req, res) => {
- res.write(data)
- res.end()
- }, cb),
- expectedResult: (cb) => {
- ipfs.add([{ path: filename, content: data }], { wrapWithDirectory: true }, cb)
- }
- }, (err, taskResult) => {
- expect(err).to.not.exist()
-
- const { server, expectedResult } = taskResult
- const url = `http://127.0.0.1:${server.address().port}/${filename}?foo=bar#buzz`
-
- ipfs.util.addFromURL(url, { wrapWithDirectory: true }, (err, result) => {
- expect(err).to.not.exist()
- expect(result).to.deep.equal(expectedResult)
- done()
- })
- })
- })
-
- it('with wrap-with-directory=true and URL-escaped file name', (done) => {
- const filename = '320px-Domažlice,_Jiráskova_43_(9102).jpg'
- const data = Buffer.from(`TEST${Date.now()}`)
-
- parallel({
- server: (cb) => startTestServer((req, res) => {
- res.write(data)
- res.end()
- }, cb),
- expectedResult: (cb) => {
- ipfs.add([{ path: filename, content: data }], { wrapWithDirectory: true }, cb)
- }
- }, (err, taskResult) => {
- expect(err).to.not.exist()
-
- const { server, expectedResult } = taskResult
- const url = `http://127.0.0.1:${server.address().port}/${encodeURIComponent(filename)}?foo=bar#buzz`
-
- ipfs.util.addFromURL(url, { wrapWithDirectory: true }, (err, result) => {
- expect(err).to.not.exist()
- expect(result).to.deep.equal(expectedResult)
- done()
- })
- })
- })
-
- it('with invalid url', (done) => {
- ipfs.util.addFromURL('http://invalid', (err, result) => {
- expect(err.code).to.equal('ENOTFOUND')
- expect(result).to.not.exist()
- done()
- })
- })
- })
-
describe('.getEndpointConfig', () => {
it('should return the endpoint configured host and port', function () {
const endpoint = ipfs.util.getEndpointConfig()