AsyncFile.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. using System.IO;
  2. namespace MediaBrowser.Model.IO
  3. {
  4. /// <summary>
  5. /// Helper class to create async <see cref="FileStream" />s.
  6. /// </summary>
  7. public static class AsyncFile
  8. {
  9. /// <summary>
  10. /// Opens an existing file for reading.
  11. /// </summary>
  12. /// <param name="path">The file to be opened for reading.</param>
  13. /// <returns>A read-only <see cref="FileStream" /> on the specified path.</returns>
  14. public static FileStream OpenRead(string path)
  15. => new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
  16. /// <summary>
  17. /// Opens an existing file for writing.
  18. /// </summary>
  19. /// <param name="path">The file to be opened for writing.</param>
  20. /// <returns>An unshared <see cref="FileStream" /> object on the specified path with Write access.</returns>
  21. public static FileStream OpenWrite(string path)
  22. => new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
  23. }
  24. }