-
Notifications
You must be signed in to change notification settings - Fork 8
Updated to handle download large files. #14
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,18 +156,15 @@ public async Task<bool> DownloadFile( | |
| throw new InvalidOperationException(string.Format("File {0} already exists.", pathname)); | ||
| } | ||
|
|
||
| using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) | ||
| { | ||
| return await ReadStream(fileStream, path, offset, length, buffersize); | ||
| } | ||
| return await ReadStream(filePath, path, offset, length, buffersize); | ||
| } | ||
|
|
||
| /// <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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| string path, | ||
| long? offset = null, | ||
| long? length = null, | ||
|
|
@@ -184,12 +181,13 @@ public async Task<bool> ReadStream( | |
| var response = await _httpClient.GetAsync(requestPath); | ||
| if (response.StatusCode.Equals(HttpStatusCode.TemporaryRedirect)) | ||
| { | ||
| var response2 = await _httpClient.GetAsync(response.Headers.Location); | ||
| response2.EnsureSuccessStatusCode(); | ||
| if (response2.IsSuccessStatusCode) | ||
| var response2 = await _httpClient.GetAsync(response.Headers.Location, HttpCompletionOption.ResponseHeadersRead); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| using (var streamToRead = await response2.Content.ReadAsStreamAsync()) | ||
| using (Stream streamToWriteTo = File.Open(filePath, FileMode.Create)) | ||
| { | ||
| await response2.Content.CopyToAsync(stream); | ||
| await streamToRead.CopyToAsync(streamToWriteTo); | ||
| } | ||
| response2.EnsureSuccessStatusCode(); | ||
| return response2.IsSuccessStatusCode; | ||
| } | ||
| throw new InvalidOperationException("Should get a 307. Instead we got: " + | ||
|
|
||
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.