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
Implements BEP53 to allow file selection using &so in magnetURIs #1396
Changes from 1 commit
File filter...
Jump to…
Implements BEP53 to allow file selection using &so in magnetURI.
- Loading branch information
| @@ -30,6 +30,7 @@ var speedometer = require('speedometer') | ||
| var uniq = require('uniq') | ||
| var utMetadata = require('ut_metadata') | ||
| var utPex = require('ut_pex') // browser exclude | ||
| var parseRange = require('parse-numeric-range') | ||
|
|
||
| var File = require('./file') | ||
| var Peer = require('./peer') | ||
| @@ -482,11 +483,6 @@ Torrent.prototype._onMetadata = function (metadata) { | ||
| }) | ||
| } | ||
|
|
||
| // start off selecting the entire torrent with low priority | ||
| if (self.pieces.length !== 0) { | ||
| self.select(0, self.pieces.length - 1, false) | ||
| } | ||
|
|
||
| self._rarityMap = new RarityMap(self) | ||
|
|
||
| self.store = new ImmediateChunkStore( | ||
| @@ -509,6 +505,22 @@ Torrent.prototype._onMetadata = function (metadata) { | ||
| return new File(self, file) | ||
| }) | ||
|
|
||
| // Only select specified files (BEP53) | ||
|
||
| if (self.so) { | ||
| var specificFiles = parseRange.parse(self.so) | ||
feross
Member
|
||
| // https://github.com/webtorrent/webtorrent/issues/164 | ||
| self.deselect(0, self.pieces.length - 1, false) | ||
feross
Member
|
||
|
|
||
| self.files.forEach(function (v, i) { | ||
| specificFiles.indexOf(i) === -1 ? self.files[i].deselect() : self.files[i].select(true) | ||
feross
Member
|
||
| }) | ||
| } else { | ||
| // start off selecting the entire torrent with low priority | ||
| if (self.pieces.length !== 0) { | ||
| self.select(0, self.pieces.length - 1, false) | ||
| } | ||
| } | ||
|
|
||
| self._hashes = self.pieces | ||
|
|
||
| self.pieces = self.pieces.map(function (hash, i) { | ||
Can you add an actual link to the BEP in this comment?