|
|
|
|
@@ -60,16 +60,37 @@ public static class File
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ReadAllText(IOPath file) => ReadAllBytes(file).BytesToString(StringConverter.UTF8);
|
|
|
|
|
|
|
|
|
|
public static async Task<byte[]> ReadAllBytesAsync(IOPath file)
|
|
|
|
|
{
|
|
|
|
|
using System.IO.FileStream stream = OpenRead(file);
|
|
|
|
|
int size = GetSize(file).ToInt();
|
|
|
|
|
byte[] output = new byte[size];
|
|
|
|
|
if (await stream.ReadAsync(output, 0, size).ConfigureAwait(false) < size)
|
|
|
|
|
throw new Exception("can't read all bytes");
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ReadAllText(IOPath file) =>
|
|
|
|
|
ReadAllBytes(file).BytesToString(StringConverter.UTF8);
|
|
|
|
|
public static async Task<string> ReadAllTextAsync(IOPath file) =>
|
|
|
|
|
(await ReadAllBytesAsync(file)).BytesToString(StringConverter.UTF8);
|
|
|
|
|
|
|
|
|
|
public static void WriteAllBytes(IOPath file, byte[] content)
|
|
|
|
|
{
|
|
|
|
|
using System.IO.FileStream stream = OpenWrite(file);
|
|
|
|
|
stream.Write(content, 0, content.Length);
|
|
|
|
|
}
|
|
|
|
|
public static async Task WriteAllBytesAsync(IOPath file, byte[] content)
|
|
|
|
|
{
|
|
|
|
|
using System.IO.FileStream stream = OpenWrite(file);
|
|
|
|
|
await stream.WriteAsync(content, 0, content.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void WriteAllText(IOPath file, string content) =>
|
|
|
|
|
WriteAllBytes(file, content.ToBytes(StringConverter.UTF8));
|
|
|
|
|
public static async Task WriteAllText(IOPath file, string content) =>
|
|
|
|
|
await WriteAllBytesAsync(file, content.ToBytes(StringConverter.UTF8));
|
|
|
|
|
public static async Task WriteAllTextAsync(IOPath file, string content) =>
|
|
|
|
|
await WriteAllBytesAsync(file, content.ToBytes(StringConverter.UTF8));
|
|
|
|
|
|
|
|
|
|
public static void AppendAllBytes(IOPath file, byte[] content)
|
|
|
|
|
{
|
|
|
|
|
@@ -77,9 +98,18 @@ public static class File
|
|
|
|
|
stream.Write(content, 0, content.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task AppendAllBytesAsync(IOPath file, byte[] content)
|
|
|
|
|
{
|
|
|
|
|
using System.IO.FileStream stream = OpenAppend(file);
|
|
|
|
|
await stream.WriteAsync(content, 0, content.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AppendAllText(IOPath file, string content) =>
|
|
|
|
|
AppendAllBytes(file, content.ToBytes(StringConverter.UTF8));
|
|
|
|
|
|
|
|
|
|
public static async Task AppendAllTextAsync(IOPath file, string content) =>
|
|
|
|
|
await AppendAllBytesAsync(file, content.ToBytes(StringConverter.UTF8));
|
|
|
|
|
|
|
|
|
|
public static System.IO.FileStream OpenRead(IOPath file)
|
|
|
|
|
{
|
|
|
|
|
if (!Exists(file))
|
|
|
|
|
|