mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 04:18:06 +02:00
Remove duplicate code and use using to properly dispose the response stream
This commit is contained in:
parent
e7e7d96f51
commit
fb7de2f966
1 changed files with 3 additions and 14 deletions
|
@ -539,22 +539,11 @@ namespace Emby.Server.Implementations.HttpClientManager
|
||||||
|
|
||||||
var contentLength = GetContentLength(httpResponse);
|
var contentLength = GetContentLength(httpResponse);
|
||||||
|
|
||||||
if (contentLength.HasValue)
|
|
||||||
{
|
|
||||||
using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
|
||||||
{
|
|
||||||
await httpResponse.GetResponseStream().CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// We're not able to track progress
|
|
||||||
using (var stream = httpResponse.GetResponseStream())
|
using (var stream = httpResponse.GetResponseStream())
|
||||||
using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
options.Progress.Report(100);
|
options.Progress.Report(100);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue