Added Extensions.cs.
Added GoldbergGlobalConfiguration. Code cleanup.
This commit is contained in:
parent
a34ed8881d
commit
508d23da5f
5 changed files with 74 additions and 44 deletions
20
GoldbergGUI.Core/Utils/Extensions.cs
Normal file
20
GoldbergGUI.Core/Utils/Extensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue