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

Conversation

@SilentBot1
Copy link
Member

SilentBot1 commented May 18, 2018

This pull request implements BEP53 as requested in #1395.

If &so= is specified, all pieces are deselected and only the pieces which contain parts of the selected files are downloaded, if no pieces are specified, the entire file is left deselected.

The use of parse-numeric-range allows for ranges to be specified in three different formats which include using hyphens, which is what the BEP calls for, e.g. 1-5 which is equal to [1, 2, 3, 4, 5], using two dots e.g. 1..5 which is also equal to [1, 2, 3, 4, 5] or by using three dots e.g. 1...5 which would equal [1, 2, 3, 4].

Any feedback or suggestions are welcome.

@SilentBot1 SilentBot1 requested a review from feross May 18, 2018
@welcome

This comment has been minimized.

Copy link

welcome bot commented May 18, 2018

Thanks for opening this pull request! Please check out our contributing guidelines.

@feross
feross approved these changes May 18, 2018
Copy link
Member

feross left a comment

Thanks for the PR. Looks really good! I shared some feedback inline. Once you've addressed it, we can merge it and release a new version :)

if (self.so) {
var specificFiles = parseRange.parse(self.so)
// https://github.com/webtorrent/webtorrent/issues/164
self.deselect(0, self.pieces.length - 1, false)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

I believe that this line should not be necessary since you moved the self.select(0, self.pieces.length - 1, false) call to an else block below. So, what is this actually deselecting?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Initially I had the if (self.so) statement under self.select all without the else statement, this is leftover code from that which can be removed, removed in next commit.

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

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Can we name this variable selectOnlyFiles, since "so" stands for "select only"?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Of course, that would also make it more clear for people searching the code.

@@ -509,6 +505,22 @@ Torrent.prototype._onMetadata = function (metadata) {
return new File(self, file)
})

// Only select specified files (BEP53)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Can you add an actual link to the BEP in this comment?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Can do, included in next commit.

self.deselect(0, self.pieces.length - 1, false)

self.files.forEach(function (v, i) {
specificFiles.indexOf(i) === -1 ? self.files[i].deselect() : self.files[i].select(true)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Unless I'm missing something, it shouldn't be necessary to call deselect() since all files start out deselected. Can we change this to just call select()?

Also, can you using array.includes() instead of array.indexOf() since it's clearer?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

You're correct, the self.files[i].deselect() serves no purpose as pieces start out deselected, this will be removed in the next commit.

Replacing specificFiles.indexOf(i) with selectOnlyFiles.includes(i) for clarity will also be in the next commit.

Thank you for the review :)

@SilentBot1 SilentBot1 merged commit 925bb88 into webtorrent:master May 18, 2018
4 checks passed
4 checks passed
Node Security No known vulnerabilities found
Details
WIP ready for review
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@welcome

This comment has been minimized.

Copy link

welcome bot commented May 18, 2018

Congrats on getting your first pull request landed!

@feross

This comment has been minimized.

Copy link
Member

feross commented May 23, 2018

@SilentBot1 Thanks for making the changes and merging. Released as 0.100.0.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.