/// <summary>
        /// Reads the entire contents of a file to a string.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="path">File to read.</param>
        /// <returns>String of the file contents, or null if the file could not be read.</returns>
        public static string ReadAllText(this IWritableDirProvider provider, ResourcePath path)
        {
            using var stream = provider.OpenRead(path);
            using var reader = new StreamReader(stream, EncodingHelpers.UTF8);

            return(reader.ReadToEnd());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reads the entire contents of a path to a byte array.
 /// </summary>
 /// <param name="provider">The writable directory to look for the path in.</param>
 /// <param name="path">The path to read the contents from.</param>
 /// <returns>The contents of the path as a byte array.</returns>
 public static byte[] ReadAllBytes(this IWritableDirProvider provider, ResourcePath path)
 {
     using var stream       = provider.OpenRead(path);
     using var memoryStream = new MemoryStream((int)stream.Length);
     stream.CopyTo(memoryStream);
     return(memoryStream.ToArray());
 }