aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/IO
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Model/IO')
-rw-r--r--MediaBrowser.Model/IO/AsyncFile.cs34
-rw-r--r--MediaBrowser.Model/IO/IFileSystem.cs4
2 files changed, 36 insertions, 2 deletions
diff --git a/MediaBrowser.Model/IO/AsyncFile.cs b/MediaBrowser.Model/IO/AsyncFile.cs
new file mode 100644
index 000000000..b888a4163
--- /dev/null
+++ b/MediaBrowser.Model/IO/AsyncFile.cs
@@ -0,0 +1,34 @@
+using System;
+using System.IO;
+
+namespace MediaBrowser.Model.IO
+{
+ /// <summary>
+ /// Helper class to create async <see cref="FileStream" />s.
+ /// </summary>
+ public static class AsyncFile
+ {
+ /// <summary>
+ /// Gets a value indicating whether we should use async IO on this platform.
+ /// <see href="https://github.com/dotnet/runtime/issues/16354" />.
+ /// </summary>
+ /// <returns>Returns <c>false</c> on Windows; otherwise <c>true</c>.</returns>
+ public static bool UseAsyncIO => !OperatingSystem.IsWindows();
+
+ /// <summary>
+ /// Opens an existing file for reading.
+ /// </summary>
+ /// <param name="path">The file to be opened for reading.</param>
+ /// <returns>A read-only <see cref="FileStream" /> on the specified path.</returns>
+ public static FileStream OpenRead(string path)
+ => new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, IODefaults.FileStreamBufferSize, UseAsyncIO);
+
+ /// <summary>
+ /// Opens an existing file for writing.
+ /// </summary>
+ /// <param name="path">The file to be opened for writing.</param>
+ /// <returns>An unshared <see cref="FileStream" /> object on the specified path with Write access.</returns>
+ public static FileStream OpenWrite(string path)
+ => new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, UseAsyncIO);
+ }
+}
diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs
index be4f1e16b..0f77d6b5b 100644
--- a/MediaBrowser.Model/IO/IFileSystem.cs
+++ b/MediaBrowser.Model/IO/IFileSystem.cs
@@ -51,7 +51,7 @@ namespace MediaBrowser.Model.IO
/// <returns>A <see cref="FileSystemMetadata" /> object.</returns>
/// <remarks><para>If the specified path points to a directory, the returned <see cref="FileSystemMetadata" /> object's
/// <see cref="FileSystemMetadata.IsDirectory" /> property and the <see cref="FileSystemMetadata.Exists" /> property will both be set to false.</para>
- /// <para>For automatic handling of files <b>and</b> directories, use <see cref="M:IFileSystem.GetFileSystemInfo(System.String)" />.</para></remarks>
+ /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo(string)" />.</para></remarks>
FileSystemMetadata GetFileInfo(string path);
/// <summary>
@@ -61,7 +61,7 @@ namespace MediaBrowser.Model.IO
/// <returns>A <see cref="FileSystemMetadata" /> object.</returns>
/// <remarks><para>If the specified path points to a file, the returned <see cref="FileSystemMetadata" /> object's
/// <see cref="FileSystemMetadata.IsDirectory" /> property will be set to true and the <see cref="FileSystemMetadata.Exists" /> property will be set to false.</para>
- /// <para>For automatic handling of files <b>and</b> directories, use <see cref="M:IFileSystem.GetFileSystemInfo(System.String)" />.</para></remarks>
+ /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo(string)" />.</para></remarks>
FileSystemMetadata GetDirectoryInfo(string path);
/// <summary>