Browse Source

Move DownloadToFileAsync's buffersize to class const

Simply calls
pull/18/head
Ionite 1 year ago
parent
commit
d8bf934043
No known key found for this signature in database
  1. 5
      StabilityMatrix/Services/DownloadService.cs
  2. 2
      StabilityMatrix/Services/IDownloadService.cs

5
StabilityMatrix/Services/DownloadService.cs

@ -13,6 +13,7 @@ public class DownloadService : IDownloadService
{
private readonly ILogger<DownloadService> logger;
private readonly IHttpClientFactory httpClientFactory;
private const int BufferSize = ushort.MaxValue;
public DownloadService(ILogger<DownloadService> logger, IHttpClientFactory httpClientFactory)
{
@ -20,7 +21,7 @@ public class DownloadService : IDownloadService
this.httpClientFactory = httpClientFactory;
}
public async Task DownloadToFileAsync(string downloadUrl, string downloadLocation, int bufferSize = ushort.MaxValue,
public async Task DownloadToFileAsync(string downloadUrl, string downloadLocation,
IProgress<ProgressReport>? progress = null, string? httpClientName = null)
{
using var client = string.IsNullOrWhiteSpace(httpClientName)
@ -51,7 +52,7 @@ public class DownloadService : IDownloadService
await using var stream = await response.Content.ReadAsStreamAsync();
var totalBytesRead = 0L;
var buffer = new byte[bufferSize];
var buffer = new byte[BufferSize];
while (true)
{
var bytesRead = await stream.ReadAsync(buffer);

2
StabilityMatrix/Services/IDownloadService.cs

@ -6,6 +6,6 @@ namespace StabilityMatrix.Services;
public interface IDownloadService
{
Task DownloadToFileAsync(string downloadUrl, string downloadLocation, int bufferSize = ushort.MaxValue,
Task DownloadToFileAsync(string downloadUrl, string downloadLocation,
IProgress<ProgressReport>? progress = null, string? httpClientName = null);
}

Loading…
Cancel
Save