Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport for byte range requests on file urls #22024
Conversation
highfive
commented
Oct 26, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Oct 26, 2018
|
r? @jdm |
| body.extend_from_slice(&buffer); | ||
| let offset = usize::min({ | ||
| if let Some(end) = end { | ||
| let remaining_bytes = end as usize - body.len(); |
This comment has been minimized.
This comment has been minimized.
jdm
Oct 30, 2018
Member
Don't we need to include start in this calculation? Otherwise end could be much larger than body.len() even if the range is small, and we could end up with a lot of unnecessary data in the buffer.
This comment has been minimized.
This comment has been minimized.
ferjm
Oct 30, 2018
•
Author
Member
Hmm... I believe we don't need to include start here. remaining_bytes is used to identify the last chunk of data and its size, which will likely be different to FILE_CHUNK_SIZE.
But your comment made me realize that end could be larger than the file size, and so we need to narrow it down in that case.
This comment has been minimized.
This comment has been minimized.
jdm
Oct 30, 2018
Member
Imagine FILE_CHUNK_SIZE = 10, the total file is 1000 bytes long, and the range is [500, 599]. There will be 9 iterations of reading FILE_CHUNK_SIZE bytes and appending them to body. On the 10th iteration, remaining_bytes will be 509 (599-90), which is greater than FILE_CHUNK_SIZE. We will then append FILE_CHUNK_SIZE bytes to body (10), which exceeds the actual range we want, and then continue appending more data until we either run out of file content, or the end - body.len() calculation is less than FILE_CHUNK_SIZE.
This comment has been minimized.
This comment has been minimized.
ferjm
Oct 31, 2018
Author
Member
Of course, you are absolutely right. Thanks for the detailed explanation.
|
Test-tidy is unhappy. |
|
Fixed and added some tests |
|
@bors-servo r+ |
|
|
Support for byte range requests on file urls - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors This is required to allow seeking on media behind file urls <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22024) <!-- Reviewable:end -->
|
|
ferjm commentedOct 26, 2018
•
edited by SimonSapin
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis is required to allow seeking on media behind file urls
This change is