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

Downloading Whole Torrent. #111

Closed
arch-linux opened this issue Apr 22, 2015 · 7 comments
Closed

Downloading Whole Torrent. #111

arch-linux opened this issue Apr 22, 2015 · 7 comments
Labels

Comments

@arch-linux
Copy link

Hello,
This module seems to be the best fit, but i can't seem to get it to function properly at all.
For the record, I am trying to use this as a torrent downloader, so it will write the torrent to a file..

var torrentStream = require('torrent-stream');

var engine = torrentStream('magnent here');

engine.on('ready', function() {
engine.files.forEach(function(file) {
if(file.name == "filename here.") {
var stream = file.createReadStream();
}
});
});

How can i make this code download all of the files in the torrent, and save them to the disk?

Thank you!

@asapach
Copy link
Collaborator

asapach commented Apr 22, 2015

You should call select() on each file instead of createReadStream(). When all the files are downloaded, the engine will emit an 'uninterested' event.

@mafintosh
Copy link
Owner

Here is a full snippet showing what @asapach is talking about:

var engine = torrentStream(someTorrent, {
  path: 'the-folder-you-want-to-store-the-files-in'
})

engine.on('ready', function () {
  engine.files.forEach(function (file) {
    file.select()
  })
  engine.on('idle', function () {
    console.log('all files downloaded!')
  })
})

@asapach
Copy link
Collaborator

asapach commented Apr 22, 2015

@mafintosh, which reminds me, there should be a dedicated event for when the download is complete. That would allow us to fix #109 and #48.

@mafintosh
Copy link
Owner

@asapach should we call it engine.on('downloaded', fn) or do you have a better idea?

@asapach
Copy link
Collaborator

asapach commented Apr 22, 2015

@mafintosh, 'downloaded' or 'complete' work for me.

@arch-linux
Copy link
Author

I appreciate it you guys.
I was able to get it to work!

@asapach
Copy link
Collaborator

asapach commented Apr 23, 2015

see #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants