Update Connection#download method to stream data #248
Merged
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.
The download method waits for the entire response body before returning the data to the caller or storing it into a file. This change implements streaming the request to accommodate large file/report downloads.
Description
Streams the HTTP Response body to a file, allows for the caller to pass in a block, and maintains the default behaviour of the method to avoid needing changes.
Motivation and Context
I was seeing weird timeout and Errno::EINVAL issues that were thrown when large (4GB) report downloads were requested. This addresses those.
How Has This Been Tested?
Used to download 100 reports of sizes ranging from 5KB to 5GB and successfully completed all of them.
No impact to existing code
Screenshots (if appropriate):
Types of changes
Checklist:
I have added tests to cover my changes.Large file downloads can cause timeout issues and odd Errno::EINVAL errors to be raised. This update provides a way to stream the contents of the response body to a file, yield a block, and maintains the original behavior if desired.