Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torrent.files[i].done is always false, even if file is fully downloaded #829

Closed
romaincointepas opened this issue Jun 7, 2016 · 4 comments
Closed

Comments

@romaincointepas
Copy link

@romaincointepas romaincointepas commented Jun 7, 2016

  • WebTorrent version: 0.94.3
  • Node.js version: 6.1.0
  • Electron version: 1.2.1

However, if I console.log(torrent.files[i]), I see done: true.

Any idea?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 7, 2016

Sounds like it's probably a bug in your code. Are you checking the value of torrent.files[i] done before the file is actually done?

@romaincointepas

This comment has been minimized.

Copy link
Author

@romaincointepas romaincointepas commented Jun 8, 2016

The file is done for sure.

I'm checking for file.done in the client.add callback (reopen the app with a torrent/file that has been downloaded in a previous session).

I'm also in an Electron renderer, if that matters.

Here is a quick test code:

client.add magnetURL, (torrent) ->
    file = torrent.files[0]
    console.log 'PRE-TEST'
    console.log file.done
    console.log file
    console.log file.done
    console.log 'POST-TEST'

And here is what I get in the Console:

Update
Checking for file.done next tick (process.nextTick()) shows true (the correct value). Is that expected behavior?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 11, 2016

The file won't be done immediately when the onTorrent callback is called. You can listen for the 'done' event to find out when the file is done:

client.add(magnet, function (torrent) {
  var file = torrent.files[0]
  file.on('done', function () {
    file.done // true
  })
})

You're seeing that it's true when you expand the object in the inspector because the developer tools just save a reference to the object and don't resolve the values of it's properties until you expand the object.

If you hover over the 'i' icon in the interface you'll see:

screen shot 2016-06-10 at 22 48 14

@feross feross closed this Jun 11, 2016
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.