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

Persisting torrent download state #456

Closed
lucaswxp opened this issue Oct 8, 2015 · 2 comments
Closed

Persisting torrent download state #456

lucaswxp opened this issue Oct 8, 2015 · 2 comments
Labels

Comments

@lucaswxp
Copy link
Contributor

@lucaswxp lucaswxp commented Oct 8, 2015

Hey guys, nice job!

I have a question, if I start downloading a file like this:

var WebTorrent = require('webtorrent')

var client = new WebTorrent()
var magnetUri = '...'

client.download(magnetUri, function (torrent) {
})

And the download reaches 50%, but for some reason my server crashes, if I restart the server, and add the same torrent again with the same destination path, will it continue downloading from where it stopped?

Also, there's any event in client that notifies when a torrent was completed?

@lucaswxp

This comment has been minimized.

Copy link
Contributor Author

@lucaswxp lucaswxp commented Oct 9, 2015

Alright,

I have done some testing and apparently the torrent starts from where it left off.

Also, the event I was looking for is called 'done' in the torrent object itself.

Code example:

client.download(magnetUri, {path: process.cwd() + '/data'}, function (torrent) {
      // Got torrent metadata!
      console.log('Torrent info hash:', torrent.infoHash)
      console.log('Save location: ' + torrent.path);

      // this is called every time we receive a chunk
      torrent.on('download', function(chunkSize){
        console.log('chunk size: ' + chunkSize);
        console.log('total downloaded: ' + torrent.downloaded);
        console.log('download speed: ' + torrent.downloadSpeed());
        console.log('progress: ' + torrent.progress);
        console.log('======');
      })

      torrent.on('done', function(){
        console.log('torrent downloaded!');
        torrent.files.forEach(function(file){
           // do something with file
        })
      })
    })
@lucaswxp lucaswxp closed this Oct 9, 2015
@feross feross added the question label Feb 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.