From f67d87aceeb756d1e658051af894da02e51eec15 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 6 Oct 2017 10:25:27 -0600 Subject: [PATCH 1/3] feat: add progress bar tests --- src/files.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/files.js b/src/files.js index 74a39247..996b467a 100644 --- a/src/files.js +++ b/src/files.js @@ -123,6 +123,28 @@ module.exports = (common) => { }) }) + it('BIG buffer with progress', (done) => { + const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' + + let progCount = 0 + let progress = 0 + const handler = (p) => { + progCount += 1 + progress = p + } + + ipfs.files.add(bigFile, {progress: handler}, (err, res) => { + expect(err).to.not.exist() + expect(res).to.have.length(1) + const file = res[0] + expect(file.hash).to.equal(expectedMultihash) + expect(file.path).to.equal(file.hash) + expect(progCount).to.equal(58) + expect(progress).to.equal(57792) + done() + }) + }) + it('add a nested dir as array', (done) => { // Needs https://github.com/ipfs/js-ipfs-api/issues/339 to be fixed // for js-ipfs-api + go-ipfs @@ -160,6 +182,52 @@ module.exports = (common) => { }) }) + it('add a nested dir as array with progress', (done) => { + // Needs https://github.com/ipfs/js-ipfs-api/issues/339 to be fixed + // for js-ipfs-api + go-ipfs + if (!isNode) { return done() } + + const content = (name) => ({ + path: `test-folder/${name}`, + content: directoryContent[name] + }) + + const emptyDir = (name) => ({ + path: `test-folder/${name}` + }) + + const expectedRootMultihash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' + + const dirs = [ + content('pp.txt'), + content('holmes.txt'), + content('jungle.txt'), + content('alice.txt'), + emptyDir('empty-folder'), + content('files/hello.txt'), + content('files/ipfs.txt'), + emptyDir('files/empty') + ] + + let progCount = 0 + let progress = 0 + const handler = (p) => { + progCount += 1 + progress = p + } + + ipfs.files.add(dirs, {progress: handler}, (err, res) => { + expect(err).to.not.exist() + const root = res[res.length - 1] + + expect(root.path).to.equal('test-folder') + expect(root.hash).to.equal(expectedRootMultihash) + expect(progCount).to.equal(8) + expect(progress).to.equal(5) + done() + }) + }) + describe('.createAddStream', () => { it('stream of valid files and dirs', (done) => { const content = (name) => ({ From d30fddebc7621dafd7ba52db302477a0bf231b68 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 10 Oct 2017 00:08:50 -0600 Subject: [PATCH 2/3] feat: fixing progress bar tests --- src/files.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/files.js b/src/files.js index 996b467a..28f57e49 100644 --- a/src/files.js +++ b/src/files.js @@ -130,7 +130,7 @@ module.exports = (common) => { let progress = 0 const handler = (p) => { progCount += 1 - progress = p + progress += p } ipfs.files.add(bigFile, {progress: handler}, (err, res) => { @@ -140,7 +140,7 @@ module.exports = (common) => { expect(file.hash).to.equal(expectedMultihash) expect(file.path).to.equal(file.hash) expect(progCount).to.equal(58) - expect(progress).to.equal(57792) + expect(progress).to.equal(bigFile.byteLength) done() }) }) @@ -209,11 +209,15 @@ module.exports = (common) => { emptyDir('files/empty') ] + const total = dirs.reduce((i, entry) => { + return i + (entry.content ? entry.content.length : 0) + }, 0) + let progCount = 0 let progress = 0 const handler = (p) => { progCount += 1 - progress = p + progress += p } ipfs.files.add(dirs, {progress: handler}, (err, res) => { @@ -223,7 +227,7 @@ module.exports = (common) => { expect(root.path).to.equal('test-folder') expect(root.hash).to.equal(expectedRootMultihash) expect(progCount).to.equal(8) - expect(progress).to.equal(5) + expect(progress).to.equal(total) done() }) }) From 4c0eca06b0d20a64a54c4e8aa5d5441b3ea9bf25 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 14 Oct 2017 17:39:45 -0700 Subject: [PATCH 3/3] feat: documenting add options --- API/files/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/API/files/README.md b/API/files/README.md index 724a110b..353782c2 100644 --- a/API/files/README.md +++ b/API/files/README.md @@ -23,7 +23,11 @@ Where `data` may be If no `content` is passed, then the path is treated as an empty directory -`options` is an optional object argument containing the [DAG importer options](https://github.com/ipfs/js-ipfs-unixfs-engine#importer-api). +`options` is an optional object argument that might include the following keys: + +- cid-version (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, including it's version) +- progress (function): a function that will be called with the byte length of chunks as a file is added to ipfs. +- hashAlg || hash (string): multihash hashing algorithm to use `callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` will be an array of: