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

Is it possible to pipe the torrent files to a spawn while downloading at the same time? #608

Closed
shirotech opened this issue Feb 9, 2016 · 4 comments
Labels

Comments

@shirotech
Copy link

@shirotech shirotech commented Feb 9, 2016

Seems like a pretty nice library, was wondering if the following scenario is possible, the use case is not having to save the files physically to a disk, which would allow uploading directly to a remote server.

torrentStream.pipe(child.spawn('acd_cli', ['stream', filename, conf.folder]).stdin);

Would something like this be feasible?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Feb 9, 2016

Yep that should work just fine. You can get a torrent file as a stream like this:

var WebTorrent = require('webtorrent')
var client = new WebTorrent()
client.add(magnet_uri, function (torrent) {
  var file = torrent.files[0] // get the file you want to upload
  file.createReadStream().pipe(/* your child process stdin */)
})
@feross feross added the question label Feb 9, 2016
@feross feross closed this Feb 9, 2016
@shirotech

This comment has been minimized.

Copy link
Author

@shirotech shirotech commented Feb 9, 2016

@feross Yes, but it still writes to /tmp/webtorrent would it work if I make the path to /dev/null? Thanks.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Feb 10, 2016

@van-nguyen The file data needs to be available somewhere for the proper functioning of the torrent protocol, i.e. peers may ask for pieces of the file, so your client can't throw them away until you remove the torrent and leave the swarm. That's why passing /dev/null as the path probably won't work.

Instead, you can use an in-memory storage (instead of the default filesystem storage). Be warned this will keep the full file in RAM until you remove the torrent from the client, but otherwise should work fine.

Here's how to do this:

var MemoryChunkStore = require('memory-chunk-store')
var WebTorrent = require('webtorrent')

var client = new WebTorrent()
client.add(magnet_uri, { store: MemoryChunkStore }, function (torrent) {
  // ...
})

See the client.add documentation for more info.

@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.