fix(android): stream full file body, not just first 8 KB segment - #474
Open
HuuNguyen312 wants to merge 1 commit into
Open
fix(android): stream full file body, not just first 8 KB segment#474HuuNguyen312 wants to merge 1 commit into
HuuNguyen312 wants to merge 1 commit into
Conversation
ProgressReportingSource.read() wrote each chunk to the destination file via ofStream but never forwarded the bytes into the Okio sink. Buffered consumers (byteStream() / source().read()) read from that sink, so after the first 8 KB segment the buffer was empty and they saw a false EOF. isDownloadComplete() then compared a truncated bytesDownloaded (8192) against the real Content-Length and reported "Download interrupted." for any file larger than one segment. Files <= 8 KB happened to pass. Forward the chunk into the sink as well so buffered reads advance to the real end of stream. Co-Authored-By: Claude Opus 4.8 (1M context) <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
On Android, downloading any file larger than 8 KB to disk fails with
"Download interrupted."(0.24.10 regression). Files ≤ 8 KB pass.Root cause
ProgressReportingSource.read()writes each chunk to the destination file viaofStreambut never forwards the bytes into the Okiosink. Bufferedconsumers (
byteStream()/source().read()) read from that sink, so after thefirst 8 KB segment the buffer is empty and they hit a false EOF.
isDownloadComplete()then compares a truncatedbytesDownloaded(8192) againstthe real
Content-Length→ not equal →"Download interrupted.".Fix
Forward the chunk into the sink too, so buffered reads advance to the real end of
stream. One line:
Verified
Real device: a 284 KB PDF over CloudFront previously aborted at exactly 8192 bytes
(
tempBytes: 8192); with the fix it streams the full body and completes.