Added Extensions.cs.

Added GoldbergGlobalConfiguration.
Code cleanup.
This commit is contained in:
Jeddunk 2021-01-15 17:46:13 +01:00
parent a34ed8881d
commit 508d23da5f
5 changed files with 74 additions and 44 deletions

View file

@ -0,0 +1,20 @@
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace GoldbergGUI.Core.Utils
{
public static class Extensions
{
public static async Task GetFileAsync(this HttpClient client, string requestUri, Stream destination,
CancellationToken cancelToken = default)
{
var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancelToken)
.ConfigureAwait(false);
await using var download = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
await download.CopyToAsync(destination, cancelToken).ConfigureAwait(false);
if (destination.CanSeek) destination.Position = 0;
}
}
}