Skip to content

Instantly share code, notes, and snippets.

@vmandic
Created October 19, 2018 19:19
Show Gist options
  • Select an option

  • Save vmandic/d5bbf34748850628298071f1164a26c6 to your computer and use it in GitHub Desktop.

Select an option

Save vmandic/d5bbf34748850628298071f1164a26c6 to your computer and use it in GitHub Desktop.
meds-processor, p2, s6
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