diff --git a/SPEC/FILES.md b/SPEC/FILES.md index 53d429bf..87de789a 100644 --- a/SPEC/FILES.md +++ b/SPEC/FILES.md @@ -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: // A Buffer, Readable Stream or Pull Stream with the contents of the file + content: // 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 @@ -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: // A Buffer, Readable Stream or Pull Stream with the contents of the file + content: // A Buffer, Readable Stream, Pull Stream or File with the contents of the file } ``` @@ -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: // A Buffer, Readable Stream or Pull Stream with the contents of the file + content: // A Buffer, Readable Stream, Pull Stream or File with the contents of the file } ``` @@ -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 diff --git a/package.json b/package.json index b77f1377..648390ce 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 0663ad25..abdd1ae8 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -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) @@ -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() @@ -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() }) }) @@ -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() }) })