mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
Merge pull request #2837 from Bond-009/async2
Minor IAsyncDisposable improvements
This commit is contained in:
commit
c15463fa12
3 changed files with 32 additions and 21 deletions
|
@ -265,17 +265,20 @@ namespace MediaBrowser.Api.Images
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
BufferContent = false
|
BufferContent = false
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
var ext = result.ContentType.Split('/').Last();
|
var ext = result.ContentType.Split('/')[^1];
|
||||||
|
|
||||||
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
using (var stream = result.Content)
|
var stream = result.Content;
|
||||||
|
await using (stream.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
using var filestream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
|
var filestream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
|
||||||
await stream.CopyToAsync(filestream).ConfigureAwait(false);
|
await using (filestream.ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
await stream.CopyToAsync(filestream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
||||||
|
|
|
@ -299,22 +299,26 @@ namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false);
|
var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
var ext = result.ContentType.Split('/').Last();
|
var ext = result.ContentType.Split('/')[^1];
|
||||||
|
|
||||||
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
using (var stream = result.Content)
|
var stream = result.Content;
|
||||||
|
|
||||||
|
await using (stream.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
using var fileStream = new FileStream(
|
var fileStream = new FileStream(
|
||||||
fullCachePath,
|
fullCachePath,
|
||||||
FileMode.Create,
|
FileMode.Create,
|
||||||
FileAccess.Write,
|
FileAccess.Write,
|
||||||
FileShare.Read,
|
FileShare.Read,
|
||||||
IODefaults.FileStreamBufferSize,
|
IODefaults.FileStreamBufferSize,
|
||||||
true);
|
true);
|
||||||
|
await using (fileStream.ConfigureAwait(false))
|
||||||
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
|
{
|
||||||
|
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
||||||
|
|
|
@ -209,24 +209,28 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written
|
// Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written
|
||||||
using var fileStream = GetPlaylistFileStream(playlist);
|
var fileStream = GetPlaylistFileStream(playlist);
|
||||||
using var reader = new StreamReader(fileStream);
|
await using (fileStream.ConfigureAwait(false))
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
while (!reader.EndOfStream)
|
|
||||||
{
|
{
|
||||||
var line = reader.ReadLine();
|
using var reader = new StreamReader(fileStream);
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1)
|
while (!reader.EndOfStream)
|
||||||
{
|
{
|
||||||
count++;
|
var line = await reader.ReadLineAsync().ConfigureAwait(false);
|
||||||
if (count >= segmentCount)
|
|
||||||
|
if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Finished waiting for {0} segments in {1}", segmentCount, playlist);
|
count++;
|
||||||
return;
|
if (count >= segmentCount)
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Finished waiting for {0} segments in {1}", segmentCount, playlist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue