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

Ipfs file upload progress #604

Merged
merged 12 commits into from
Oct 18, 2017
Merged

Ipfs file upload progress #604

merged 12 commits into from
Oct 18, 2017

Conversation

dryajov
Copy link
Contributor

@dryajov dryajov commented Oct 2, 2017

Adding this as we need this ASAP, should address #596 (comment)

bmordan and others added 2 commits October 1, 2017 18:50
Passes the progress bar option for tranfers over http. Progress is shown for your payload being streamed upto the server. There is a pause. Then you get your list of files.
*  support support specify hash alg

* Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data

* Allow object get/data to accept CID

* Var naming tweaks from review
@dryajov
Copy link
Contributor Author

dryajov commented Oct 2, 2017

pinging @skzap. This supports the progress flag for upload progress.

@dryajov dryajov changed the title Ipfs api progress Ipfs file upload progress Oct 2, 2017
@codecov
Copy link

codecov bot commented Oct 2, 2017

Codecov Report

Merging #604 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #604      +/-   ##
=========================================
+ Coverage   83.08%   83.4%   +0.31%     
=========================================
  Files         106     107       +1     
  Lines        1460    1482      +22     
=========================================
+ Hits         1213    1236      +23     
+ Misses        247     246       -1
Impacted Files Coverage Δ
src/files/add.js 89.65% <100%> (+0.36%) ⬆️
src/utils/request-api.js 93.87% <100%> (+1.83%) ⬆️
src/utils/progress-stream.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38d7289...9a11a83. Read the comment docs.

@dryajov
Copy link
Contributor Author

dryajov commented Oct 2, 2017

Seems like firefox is timing out on travis, can someone with write access rerun the build?

@@ -13,7 +13,7 @@
"devDependencies": {
"babel-core": "^5.4.7",
"babel-loader": "^5.1.2",
"ipfs-api": "^12.1.7",
"ipfs-api": "../../",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an example in the examples directory. Just repointed it to use the current ipfs-api rather than a published version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, now it makes sense 👍

expect(err).to.not.exist()

expect(res).to.have.length(1)
expect(progress).to.be.greaterThan(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should exactly be 100 right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with @victorbjelkholm

@daviddias
Copy link
Contributor

@dryajov have you tried using this with js-ipfs and see if it works for the CLI?

@daviddias daviddias self-assigned this Oct 6, 2017
expect(err).to.not.exist()

expect(res).to.have.length(1)
expect(progress).to.be.greaterThan(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with @victorbjelkholm


expect(res).to.have.length(1)
expect(progress).to.be.equal(100)
expect(progressCount).to.be.greaterThan(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not have to use greaterThan here. We should know how many times progressHandler is being called, and assert on that exactness. Not "something something above 0".

@daviddias daviddias assigned dryajov and unassigned daviddias Oct 6, 2017
@daviddias
Copy link
Contributor

daviddias commented Oct 6, 2017

@dryajov just checked and the value being returned is always 12

AssertionError: expected 12 to equal 100

Which means that go-ipfs returns an in progress, but it is not clear what this number is. Also, this feature needs to be tested with bigger files, directories and be documented.

In order to push this forward, we need:

@dryajov up to finish this PR?

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

Sure thing - I can finish this.

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

@diasdavid The cli works with - ipfs/js-ipfs#994

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

Move tests to https://github.com/ipfs/interface-ipfs-core/tree/master/src

Which tests do we want to move? All the progress ones or is that supposed to read add tests to interface-ipfs-core

I just checked the core tests - I know what this means now

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

Added interface tests - ipfs-inactive/interface-js-ipfs-core#155

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

Re: documenting feature - the docs for .add state that the options object is an expansion of https://github.com/ipfs/js-ipfs-unixfs-engine#importer-api object, which already documents this functionality:

progress (function): a function that will be called with the byte length of chunks as a file is added to ipfs.

@dryajov
Copy link
Contributor Author

dryajov commented Oct 6, 2017

update - I believe I have all the todos covered, except the Test against js-ipfs too.

I can run the js-ipfs manually and it works, but the tests are for some reason not picking up the flag, or something else is going on - I get no progress output in stdout.

@daviddias
Copy link
Contributor

Thanks for pushing this, @dryajov. See review on ipfs-inactive/interface-js-ipfs-core#155. Also, you skipped updating the docs.

@dryajov
Copy link
Contributor Author

dryajov commented Oct 9, 2017

@diasdavid RE docs: #604 (comment)

This is what I'm talking about - the docs just link to the DAG importer options, so I don't think I skipped the docs :)

options is an optional object argument containing the DAG importer options.

@daviddias
Copy link
Contributor

@dryajov good catch. That is confusing for users though. Do you mind pulling those supported options to the API doc?

@daviddias
Copy link
Contributor

@dryajov what about calling the callback with the error?

@dryajov
Copy link
Contributor Author

dryajov commented Oct 12, 2017

the problem is that the callback was already called, the only thing thats left is the stream and the through processors :(

I somehow need to make that error propagate all the way to - https://github.com/ipfs/js-ipfs-api/blob/10b0bde35a2dc106b93d52057b91265cb73a4614/src/files/add.js#L50 where that callback should get resolved once processing is finished.

@ghost ghost added the in progress label Oct 14, 2017
@dryajov
Copy link
Contributor Author

dryajov commented Oct 15, 2017

@dryajov dryajov changed the title Ipfs file upload progress Awesome progress bar functionality Oct 15, 2017
@dryajov dryajov changed the title Awesome progress bar functionality Awesome progress bar Oct 15, 2017
@dryajov
Copy link
Contributor Author

dryajov commented Oct 15, 2017

This issue is ready to ship. However, the changes in ipfs/js-ipfs#1036, currently prevent propagating errors correctly, fortunately, this should be extremely rare/catastrophic errors, i.e. out of disk space on the remote ipfs node. In order to get this working, some reworking of how responses are processed might be required, I'll open a separate issue to track that effort, but we should not hold this issues because of it.

@dryajov dryajov changed the title Awesome progress bar Ipfs file upload progress Oct 15, 2017
@dryajov dryajov mentioned this pull request Oct 15, 2017
5 tasks
@ghost ghost assigned daviddias Oct 18, 2017
@ghost ghost added the in progress label Oct 18, 2017
@daviddias
Copy link
Contributor

@dryajov tests fail locally:

Summary of all failing tests
 FAIL  test/interface/files.spec.js (5.801s)
  ● .files › callback API › .add › BIG buffer with progress

    AssertionError: expected 448324032 to equal 15000000

      at ipfs.files.add (node_modules/interface-ipfs-core/src/files.js:143:33)
      at data (src/utils/stream-to-value.js:12:18)
      at ConcatStream.<anonymous> (node_modules/concat-stream/index.js:36:43)
      at emitNone (events.js:110:20)
      at ConcatStream.emit (events.js:207:7)
      at finishMaybe (node_modules/readable-stream/lib/_stream_writable.js:607:14)
      at endWritable (node_modules/readable-stream/lib/_stream_writable.js:615:3)
      at ConcatStream.Object.<anonymous>.Writable.end (node_modules/readable-stream/lib/_stream_writable.js:571:41)
      at DAGNodeStream.onend (node_modules/readable-stream/lib/_stream_readable.js:570:10)
      at Object.onceWrapper (events.js:314:30)

  ● .files › callback API › .add › add a nested dir as array with progress

    AssertionError: expected 1386840 to equal 600408

      at ipfs.files.add (node_modules/interface-ipfs-core/src/files.js:230:33)
      at data (src/utils/stream-to-value.js:12:18)
      at ConcatStream.<anonymous> (node_modules/concat-stream/index.js:36:43)
      at emitNone (events.js:110:20)
      at ConcatStream.emit (events.js:207:7)
      at finishMaybe (node_modules/readable-stream/lib/_stream_writable.js:607:14)
      at endWritable (node_modules/readable-stream/lib/_stream_writable.js:615:3)
      at ConcatStream.Object.<anonymous>.Writable.end (node_modules/readable-stream/lib/_stream_writable.js:571:41)
      at DAGNodeStream.onend (node_modules/readable-stream/lib/_stream_readable.js:570:10)
      at Object.onceWrapper (events.js:314:30)

Am I missing something?

@dryajov
Copy link
Contributor Author

dryajov commented Oct 18, 2017

@diasdavid

There appears to be weirdness with how go-ipfs reports progress.

  • For files, it will report the total bytes transferred so far
  • For directories, the file sizes are reported for each file uploaded, in addition to that, it appears that extra bytes are being reported as well.

Here is some quick output I added to the test to track file sizes being acumulted and how they are being reported on upload.

Test Node.js
  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 4540

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 581878

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 2294

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 11685

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 0

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 6

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 5

  console.log node_modules/interface-ipfs-core/src/files.js:213
    file size is: 0

  console.log node_modules/interface-ipfs-core/src/files.js:217
    beginning upload:

  console.log node_modules/interface-ipfs-core/src/files.js:218
    ================================================

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 4540

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 262144

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 524288

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 581878

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 2294

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 11685

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 6

  console.log node_modules/interface-ipfs-core/src/files.js:223
    Progress is: 5

const ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/6001')
/* eslint-disable */
ipfs.files.add(Buffer.from('Hello there!'), (err, res) => {
// TODO: error's are not being correctly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dryajov track this in an issue.

@daviddias daviddias merged commit e2d894c into master Oct 18, 2017
@ghost ghost removed the in progress label Oct 18, 2017
@daviddias daviddias deleted the ipfs-api-progress branch October 18, 2017 15:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants