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

Implements BEP53 to allow file selection using &so in magnetURIs #1396

Merged
merged 2 commits into from May 18, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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,20 @@ Torrent.prototype._onMetadata = function (metadata) {
return new File(self, file)
})

// Select only specified files (BEP53) http://www.bittorrent.org/beps/bep_0053.html
if (self.so) {
var selectOnlyFiles = parseRange.parse(self.so)

self.files.forEach(function (v, i) {
if (selectOnlyFiles.includes(i)) self.files[i].select(true)
})
} 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) {
@@ -42,6 +42,7 @@
"mime": "^2.2.0",
"multistream": "^2.0.5",
"package-json-versionify": "^1.0.2",
"parse-numeric-range": "^0.0.2",
"parse-torrent": "^6.0.0",
"pump": "^3.0.0",
"random-iterate": "^1.0.1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.