-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue: The DownloadFileAsync method will throw an OutOfMemoryException if the file is too large #342
Issue: The DownloadFileAsync method will throw an OutOfMemoryException if the file is too large #342
Conversation
…he recording file stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but do we really need DownloadFile and DownloadFileWithoutBuffering? Why not have a single method and download all files with streaming enabled.
@@ -372,6 +367,25 @@ public Task<Stream> DownloadFileAsync(string downloadUrl, CancellationToken canc | |||
.AsStream(); | |||
} | |||
|
|||
/// <inheritdoc/> | |||
public async Task<Stream> DownloadFileWithouBufferingAsync(string downloadUrl, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you think of a downside to downloading a file without buffering? I can't think of one. Which leads me to think that all files, large or small, should probably be downloaded without buffering. Which means there's no need for a separate DownloadFileWithouBufferingAsync
method and you can move the logic to the DownloadFileAsync
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this point of view, then you are right =)
I have removed the method separating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Thank you for your contribution.
🎉 This issue has been resolved in version 0.76.0 🎉 The release is available on: Your GitReleaseManager bot 📦🚀 |
I found an issue when we use the DownloadFileAsync method. Since it uses IRequest.AsStream(), this method invokes HttpClient.SendAsync(request, cancellationtoken) and than HttpResponseMessage.Content.ReadAsStreamAsync() for the response message.
The HttpResponseMessage.Content.ReadAsStreamAsync() read whole content into the memory buffer and makes the stream from result buffer.
In our project we encountered with following issue: if we receive a large enough file, buffer can overflow.
But I also found (here Streaming Large HTTP Responses) if we call HttpClient.SendAsync with HttpCompletionOption.ResponseHeadersRead flag it just return stream without buffering and we can handle received stream as we want.
So I suggest to use old implementation of DownloadFileAsync in new method, but with HttpCompletionOption.ResponseHeadersRead flag.
May we also need to create issue in Pathoschild repository.