mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-06 10:16:18 +00:00
Use async FileStreams where it makes sense
This commit is contained in:
@@ -89,7 +89,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var attachmentPath = await GetReadableFile(mediaSource.Path, mediaSource.Path, mediaSource, mediaAttachment, cancellationToken).ConfigureAwait(false);
|
||||
return File.OpenRead(attachmentPath);
|
||||
return AsyncFile.OpenRead(attachmentPath);
|
||||
}
|
||||
|
||||
private async Task<string> GetReadableFile(
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace MediaBrowser.MediaEncoding.BdInfo
|
||||
|
||||
public bool IsDir => _impl.IsDirectory;
|
||||
|
||||
public System.IO.Stream OpenRead()
|
||||
public Stream OpenRead()
|
||||
{
|
||||
return new FileStream(
|
||||
FullName,
|
||||
@@ -33,9 +33,9 @@ namespace MediaBrowser.MediaEncoding.BdInfo
|
||||
FileShare.Read);
|
||||
}
|
||||
|
||||
public System.IO.StreamReader OpenText()
|
||||
public StreamReader OpenText()
|
||||
{
|
||||
return new System.IO.StreamReader(OpenRead());
|
||||
return new StreamReader(OpenRead());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1498,7 +1498,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
||||
{
|
||||
var packetBuffer = new byte[197];
|
||||
|
||||
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1))
|
||||
{
|
||||
fs.Read(packetBuffer);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
}
|
||||
}
|
||||
|
||||
return File.OpenRead(fileInfo.Path);
|
||||
return AsyncFile.OpenRead(fileInfo.Path);
|
||||
}
|
||||
|
||||
private async Task<SubtitleInfo> GetReadableFile(
|
||||
@@ -671,7 +671,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
string text;
|
||||
Encoding encoding;
|
||||
|
||||
using (var fileStream = File.OpenRead(file))
|
||||
using (var fileStream = AsyncFile.OpenRead(file))
|
||||
using (var reader = new StreamReader(fileStream, true))
|
||||
{
|
||||
encoding = reader.CurrentEncoding;
|
||||
@@ -684,7 +684,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
if (!string.Equals(text, newText, StringComparison.Ordinal))
|
||||
{
|
||||
// use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 .
|
||||
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, AsyncFile.UseAsyncIO))
|
||||
using (var writer = new StreamWriter(fileStream, encoding))
|
||||
{
|
||||
await writer.WriteAsync(newText.AsMemory(), cancellationToken).ConfigureAwait(false);
|
||||
@@ -750,7 +750,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
}
|
||||
|
||||
case MediaProtocol.File:
|
||||
return File.OpenRead(path);
|
||||
return AsyncFile.OpenRead(path);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(protocol));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user