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

Commit

Permalink
feat: add tests for add data using File DOM api (#461)
Browse files Browse the repository at this point in the history
* feat: add tests for add data using File DOM api

* chore: fix deps

* chore: add ipfs-utils

* chore: change to ipfs-utils

* docs: add doc s about File DOM API support

* chore: fix semver lint
  • Loading branch information
hugomrdias authored and alanshaw committed May 16, 2019
1 parent 1b3d013 commit 86a1f3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 5 additions & 3 deletions SPEC/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ Where `data` may be:
- a [`Buffer instance`][b]
- a [`Readable Stream`][rs]
- a [`Pull Stream`][ps]
- a [`File`][file]
- an array of objects, each of the form:
```JavaScript
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```
If no `content` is passed, then the path is treated as an empty directory
Expand Down Expand Up @@ -137,7 +138,7 @@ Returns a Readable Stream of class Duplex, where objects can be written of the f
```js
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```

Expand Down Expand Up @@ -185,7 +186,7 @@ Returns a Pull Stream, where objects can be written of the forms
```js
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```

Expand Down Expand Up @@ -1136,5 +1137,6 @@ A great source of [examples][] can be found in the tests for this API.
[b]: https://www.npmjs.com/package/buffer
[rs]: https://www.npmjs.com/package/readable-stream
[ps]: https://www.npmjs.com/package/pull-stream
[file]: https://developer.mozilla.org/en-US/docs/Web/API/File
[cid]: https://www.npmjs.com/package/cids
[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"into-stream": "^5.1.0",
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-utils": "~0.0.3",
"ipld-dag-cbor": "~0.13.1",
"ipld-dag-pb": "~0.15.3",
"is-ipfs": "~0.6.0",
Expand All @@ -59,7 +60,7 @@
"multihashing-async": "~0.6.0",
"peer-id": "~0.12.0",
"peer-info": "~0.15.0",
"pull-stream": "^3.6.9",
"pull-stream": "^3.6.11",
"pump": "^3.0.0",
"randombytes": "^2.0.6",
"readable-stream": "^3.1.1",
Expand Down
17 changes: 15 additions & 2 deletions src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const pull = require('pull-stream')
const path = require('path')
const expectTimeout = require('../utils/expect-timeout')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { supportsFileReader } = require('ipfs-utils/src/supports')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -35,6 +36,18 @@ module.exports = (createCommon, options) => {

after((done) => common.teardown(done))

it('should add a File', function (done) {
if (supportsFileReader) {
ipfs.add(new self.File(['should add a File'], 'filename.txt', { type: 'text/plain' }), (err, filesAdded) => {
expect(err).to.not.exist()
expect(filesAdded[0].hash).to.be.eq('QmTVfLxf3qXiJgr4KwG6UBckcNvTqBp93Rwy5f7h3mHsVC')
done()
})
} else {
this.skip('skip in node')
}
})

it('should add a Buffer', (done) => {
ipfs.add(fixtures.smallFile.data, (err, filesAdded) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -125,7 +138,7 @@ module.exports = (createCommon, options) => {

ipfs.add(data, (err) => {
expect(err).to.exist()
expect(err.message).to.contain('invalid input')
expect(err.message).to.contain('Input not supported')
done()
})
})
Expand All @@ -135,7 +148,7 @@ module.exports = (createCommon, options) => {

ipfs.add(data, (err) => {
expect(err).to.exist()
expect(err.message).to.contain('invalid input')
expect(err.message).to.contain('Input not supported')
done()
})
})
Expand Down

0 comments on commit 86a1f3f

Please sign in to comment.