Created
October 19, 2018 19:19
-
-
Save vmandic/d5bbf34748850628298071f1164a26c6 to your computer and use it in GitHub Desktop.
meds-processor, p2, s6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async Task<HzzoMedsDownloadDto> DownloadExcel(HzzoMedsDownloadDto doc) | |
| { | |
| doc.DocumentStream = await _httpCli.GetStreamAsync(doc.Href); | |
| return doc; | |
| } | |
| static Task SaveExcel(HzzoMedsDownloadDto doc) => | |
| Task.Factory.StartNew(() => | |
| { | |
| using(var fileStream = File.Create(doc.FilePath, BUFFER_SIZE, FileOptions.Asynchronous)) | |
| { | |
| CopyStream(doc.DocumentStream, fileStream); | |
| } | |
| }, TaskCreationOptions.LongRunning); | |
| /// <summary> | |
| /// Copies the contents of input to output. Doesn't close either stream. | |
| /// </summary> | |
| static void CopyStream(Stream input, Stream output) | |
| { | |
| byte[] buffer = new byte[BUFFER_SIZE]; | |
| int len; | |
| while ((len = input.Read(buffer, 0, buffer.Length)) > 0) | |
| output.Write(buffer, 0, len); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment