-
Notifications
You must be signed in to change notification settings - Fork 8
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
Updated to handle download large files. #14
base: master
Are you sure you want to change the base?
Conversation
When downloading files, the current code reads the response in memory before write the file to disk. Large files could cause the client to crash with OutOfMemoryException. Updated the client to stream the response directly to disk.
Black Duck Security ReportMerging #14 into master will not change security risk. Added ComponentsClean: 101 |
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.
{ | ||
return await ReadStream(fileStream, path, offset, length, buffersize); | ||
} | ||
return await ReadStream(filePath, path, offset, length, buffersize); |
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.
Please don't make this change. This is designed to stream to the file. You basically do the same thing with File.Open later for the stream to write to.
} | ||
|
||
/// <summary> | ||
/// https://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#Open_and_Read_a_File | ||
/// Note: You are responsible for closing the stream you send in. | ||
/// </summary> | ||
public async Task<bool> ReadStream( | ||
Stream stream, | ||
string filePath, |
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.
Please leave this as Stream stream. This breaks the public contract of the method.
var response2 = await _httpClient.GetAsync(response.Headers.Location); | ||
response2.EnsureSuccessStatusCode(); | ||
if (response2.IsSuccessStatusCode) | ||
var response2 = await _httpClient.GetAsync(response.Headers.Location, HttpCompletionOption.ResponseHeadersRead); |
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.
I think the logic here can be cleaned up to accomplish the same thing without moving the File stream around.
This PR should fix issue #13 |
@zhusulai, are you still working on this PR? Looks like good feature to have. |
When downloading files, the current code reads the response in memory before write the file to disk. Large files could cause the client to crash with OutOfMemoryException. Updated the client to stream the response directly to disk.