Repository navigation
Fix 416 when downloading files whose size is a multiple of 10 MiB - #497
Open
leifrossau wants to merge 1 commit into
Open
leifrossau wants to merge 1 commit into
leifrossau wants to merge 1 commit into
Conversation
GetItemContentStream downloads files larger than 10 MiB in 10 MiB ranges. The number of requests was size/chunk+1, which for a file whose size is an exact multiple of the chunk size (20 MiB, 30 MiB, ...) meant one extra request for a range starting at the end of the file. The server answers that with HTTP 416 and the whole download fails. Compute the ranges in chunkRanges() instead, which never produces an empty trailing range, and add a unit test for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GetItemContentStreamdownloads large files in 10 MiB Range requests. The request count wassize/chunk+1, so for a file whose size is an exact multiple of 10 MiB (20, 30, … MiB) it sent one extra request at offset == size. The server answers 416 and the whole download fails.(A file of exactly 10 MiB takes the single-request path and was not affected.)
Fix
Compute the ranges in a small pure function,
chunkRanges(), which never emits an empty trailing range. The last range end is clamped tosize-1(it used to bestart+chunk-1; servers accept both).Testing
New unit test
TestChunkRangescovering 0, chunk, chunk+1, 2×chunk and 3×chunk.go build ./...andgo vet ./...pass. I could not run the live-account test suite.🤖 Generated with Claude Code