From 5879f37967525604222ff5dd55d2dd760aca5a8b Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 2 May 2019 11:52:12 +0100 Subject: [PATCH 1/6] feat: add tests for add data using File DOM api --- src/files-regular/add.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 0663ad25c..abdd1ae87 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() }) }) From a50d91ba4afbb9ffff71e7f869dfa19619c410e3 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 3 May 2019 09:47:29 +0100 Subject: [PATCH 2/6] chore: fix deps --- src/files-regular/add.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index abdd1ae87..d487bbefb 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -7,7 +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') +const { supportsFileReader } = require('js-ipfs-utils/src/supports') module.exports = (createCommon, options) => { const describe = getDescribe(options) From 1a98fab48991204337c9ae041b7483c49fc3a32f Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 16 May 2019 16:55:49 +0200 Subject: [PATCH 3/6] chore: add ipfs-utils --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6fd4764bb..176051859 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", From 28e3d6ce3ef1f93a6bfc50ea3b15b0cc49294568 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 16 May 2019 17:02:06 +0200 Subject: [PATCH 4/6] chore: change to ipfs-utils --- src/files-regular/add.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index d487bbefb..abdd1ae87 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -7,7 +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('js-ipfs-utils/src/supports') +const { supportsFileReader } = require('ipfs-utils/src/supports') module.exports = (createCommon, options) => { const describe = getDescribe(options) From 0afa0f4c33d1864d8f7afb02fcdd2c65a25e2c22 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 16 May 2019 17:26:55 +0200 Subject: [PATCH 5/6] docs: add doc s about File DOM API support --- SPEC/FILES.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SPEC/FILES.md b/SPEC/FILES.md index 53d429bf8..87de789a9 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 From 73565ade939df8973964ab6669d7836defb0de35 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 16 May 2019 19:25:10 +0200 Subject: [PATCH 6/6] chore: fix semver lint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 176051859..9f04c40d5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "into-stream": "^5.1.0", "ipfs-block": "~0.8.0", "ipfs-unixfs": "~0.1.16", - "ipfs-utils": "^0.0.3", + "ipfs-utils": "~0.0.3", "ipld-dag-cbor": "~0.13.1", "ipld-dag-pb": "~0.15.3", "is-ipfs": "~0.6.0",