/// <summary> /// Writes the content string to a file. If the file exists, its existing contents will /// be replaced. /// </summary> /// <param name="provider"></param> /// <param name="path">Path of the file to write to.</param> /// <param name="content">String contents of the file.</param> public static void WriteAllText(this IWritableDirProvider provider, ResourcePath path, ReadOnlySpan <char> content) { using var stream = provider.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read); using var writer = new StreamWriter(stream, EncodingHelpers.UTF8); writer.Write(content); }
/// <summary> /// Opens a file for reading. /// </summary> /// <param name="provider"></param> /// <param name="path">The path of the file to open.</param> /// <returns>A valid file stream.</returns> /// <exception cref="FileNotFoundException"> /// Thrown if the file does not exist. /// </exception> public static Stream OpenRead(this IWritableDirProvider provider, ResourcePath path) { return(provider.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)); }
/// <returns>A valid file stream.</returns> public static Stream Create(this IWritableDirProvider provider, ResourcePath path) { return(provider.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None)); }
public static void WriteAllBytes(this IWritableDirProvider provider, ResourcePath path, ReadOnlySpan <byte> content) { using var stream = provider.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read); stream.Write(content); }