feat(sdk): add streaming download_to_file for devbox files#816
Open
jrvb-rl wants to merge 1 commit into
Open
Conversation
devbox.file.download() reads the entire file into memory via response.read(), which is wasteful for large downloads — the mirror image of the upload-side buffering. Add download_to_file(dest) on both the sync and async FileInterface that streams the response body to disk in chunks via with_streaming_response, so large files never have to fit in memory. The buffered download() is kept for small-file convenience. Co-Authored-By: Claude Opus 4.8 <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.
Summary
devbox.file.download()reads the entire file into memory (response.read()), the mirror image of the upload-side buffering. This addsdownload_to_file(dest)on both the sync and asyncFileInterfacethat streams the response body straight to disk in chunks viawith_streaming_response, so large downloads never have to fit in RAM.The existing
download()(returnsbytes) is kept unchanged for small-file convenience — streaming into abytesreturn is impossible by definition, so this is additive rather than a behavior change.Companion to #815 (streaming uploads).
Changes
sdk/devbox.py/sdk/async_devbox.py: newdownload_to_file(dest, *, chunk_size=None, **params)usingwith_streaming_response.download_file(...)+stream_to_file.test_download_to_file(sync + async) assert the body is streamed to disk and the correctpathis forwarded.Usage
Test plan
uv run pytest tests/sdk/devbox tests/sdk/async_devbox— 95 passedruff checkclean🤖 Generated with Claude Code