Multiple Stream changes

* Remove useless MemoryStream in DlnaHttpClient
* Use HttpContent.ReadFromJsonAsync extension
* Call ConfigureAwait for IAsyncDisposable
* Use HttpContent.CopyToAsync where possible
This commit is contained in:
Bond_009
2023-10-11 18:32:57 +02:00
parent 26571a8c51
commit d7748cfa04
25 changed files with 195 additions and 214 deletions

View File

@@ -176,17 +176,12 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
Directory.CreateDirectory(Path.GetDirectoryName(path));
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false);
var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using (stream.ConfigureAwait(false))
var fileStreamOptions = AsyncFile.WriteOptions;
fileStreamOptions.Mode = FileMode.Create;
var fs = new FileStream(path, fileStreamOptions);
await using (fs.ConfigureAwait(false))
{
var fileStreamOptions = AsyncFile.WriteOptions;
fileStreamOptions.Mode = FileMode.Create;
fileStreamOptions.PreallocationSize = stream.Length;
var xmlFileStream = new FileStream(path, fileStreamOptions);
await using (xmlFileStream.ConfigureAwait(false))
{
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false);
}
await response.Content.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
}
}