Skip to content

Fix 416 when downloading files whose size is a multiple of 10 MiB - #497

Open
leifrossau wants to merge 1 commit into
jstaf:masterfrom
leifrossau:pr/download-exact-chunk-multiple
Open

leifrossau wants to merge 1 commit into
jstaf:masterfrom
leifrossau:pr/download-exact-chunk-multiple

Conversation

@leifrossau

Copy link
Copy Markdown

Problem

GetItemContentStream downloads large files in 10 MiB Range requests. The request count was size/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 to size-1 (it used to be start+chunk-1; servers accept both).

Testing

New unit test TestChunkRanges covering 0, chunk, chunk+1, 2×chunk and 3×chunk. go build ./... and go vet ./... pass. I could not run the live-account test suite.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant