why did I start writing this plugin

This commit is contained in:
Stanley Dimant
2022-06-27 12:31:41 +02:00
parent 61b178e2c0
commit c7439ac769
7 changed files with 53 additions and 39 deletions

View File

@@ -247,19 +247,14 @@ namespace MareSynchronos.WebAPI
public async Task<string> DownloadFile(string hash, CancellationToken ct)
{
var reader = await _fileHub!.StreamAsChannelAsync<byte[]>("DownloadFile", hash, ct);
int i = 0;
var reader = _fileHub!.StreamAsync<byte[]>("DownloadFileAsync", hash, ct);
string fileName = Path.GetTempFileName();
await using var fs = File.OpenWrite(fileName);
while (await reader.WaitToReadAsync(ct) && !ct.IsCancellationRequested)
await foreach (var data in reader.WithCancellation(ct))
{
while (reader.TryRead(out var data) && !ct.IsCancellationRequested)
{
CurrentDownloads[hash] = (CurrentDownloads[hash].Item1 + data.Length, CurrentDownloads[hash].Item2);
await fs.WriteAsync(data, ct);
}
CurrentDownloads[hash] = (CurrentDownloads[hash].Item1 + data.Length, CurrentDownloads[hash].Item2);
await fs.WriteAsync(data, ct);
}
return fileName;
}