Skip to content

Extension method to conveniently download a file - #136

Open
Jericho wants to merge 10 commits into
Pathoschild:developfrom
Jericho:GH-135_download_file
Open

Jericho wants to merge 10 commits into
Pathoschild:developfrom
Jericho:GH-135_download_file

Conversation

@Jericho

@Jericho Jericho commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Download a resource, save it locally and report progress as data is being downloaded.

Resolves #135

Jericho and others added 10 commits November 15, 2026 14:04
This fixes a few edge cases:
- downloads finishing without a guaranteed 100% progress update;
- progress reporting invalid percentages (e.g. 250%) if the server provides an incorrect Content-Length;
- progress never reported if the server provides no Content-Length;
- a DivideByZeroException if the server provides a zero Content-Length.
This applies our pre-existing fixes like Pathoschild#126 to the new code.
We reported progress on every chunk read, but that could lead to a large number of callbacks when downloading a large file over a fast connection (e.g. thousands per second). The progress reports are now throttled to one per 250ms at most.
@Pathoschild

Copy link
Copy Markdown
Owner

This looks good overall; thanks for the PR!

There's one edge case I'm not sure how we should handle: when used with [Set|With]Options(ignoreHttpErrors: true), a server error will silently get downloaded as the file content, which probably isn't what the user would expect. The extension could maybe return a metadata object (e.g. { Success: false, Error: "..." }), but that might be a bit awkward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a more convenient way to download file

2 participants