/// <summary> /// Read file into string<br/> /// 读取文件内容到字符串<br/> /// </summary> /// <param name="entry">File entry</param> /// <returns></returns> public static string ReadAllText(this IFileEntry entry) { using (var stream = entry.OpenRead()) using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } }
/// <summary> /// Read file into byte array<br/> /// 读取文件到字节数组<br/> /// </summary> /// <param name="entry">File entry</param> /// <returns></returns> public static byte[] ReadAllBytes(this IFileEntry entry) { using (var stream = entry.OpenRead()) using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); return(memoryStream.ToArray()); } }
/// <summary> /// Write byte array to file /// </summary> /// <param name="entry">File entry</param> /// <param name="bytes">Byte array</param> public static void WriteAllBytes(this IFileEntry entry, byte[] bytes) { using (var stream = entry.OpenRead()) { stream.Write(bytes, 0, bytes.Length); } }