Skip to content

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

ghost 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>
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.

3 participants