Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhusulai
Copy link

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.

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.
@BlackDuckCoPilot
Copy link

BlackDuckCoPilot commented May 25, 2018

Black Duck Security Report

Merging #14 into master will not change security risk.

Added Components

Clean: 101

Click here to see full report

@risdenk risdenk self-requested a review May 25, 2018 17:46
Copy link
Owner

@risdenk risdenk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhusulai Thanks for the PR. It looks like this is related to #13. I think the idea that you are going for is good just want to minimize public facing changes.

{
return await ReadStream(fileStream, path, offset, length, buffersize);
}
return await ReadStream(filePath, path, offset, length, buffersize);
Copy link
Owner

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,
Copy link
Owner

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);
Copy link
Owner

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.

@risdenk
Copy link
Owner

risdenk commented May 25, 2018

This PR should fix issue #13

@kunalspathak
Copy link

@zhusulai, are you still working on this PR? Looks like good feature to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants