AsyncFile.cs 1.1 KB

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