haxe/src/sys/io/File.cs
// Generated by Haxe 4.3.7 (patched: in-memory file IO)
#pragma warning disable 109, 114, 219, 429, 168, 162
namespace sys.io {
public class File : global::haxe.lang.HxObject {
public File(global::haxe.lang.EmptyObject empty) {
}
public File() {
global::sys.io.File.__hx_ctor_sys_io_File(this);
}
protected static void __hx_ctor_sys_io_File(global::sys.io.File __hx_this) {
}
public static string getContent(string path) {
global::sys.io.FileInput f = global::sys.io.File.read(path, new global::haxe.lang.Null<bool>(false, true));
string ret = f.readAll(default(global::haxe.lang.Null<int>)).toString();
f.close();
return ret;
}
public static void saveContent(string path, string content) {
global::sys.io.FileOutput f = global::sys.io.File.write(path, new global::haxe.lang.Null<bool>(false, true));
f.writeString(content, null);
f.close();
}
public static global::haxe.io.Bytes getBytes(string path) {
global::sys.io.FileInput f = global::sys.io.File.read(path, new global::haxe.lang.Null<bool>(true, true));
global::haxe.io.Bytes ret = f.readAll(default(global::haxe.lang.Null<int>));
f.close();
return ret;
}
public static void saveBytes(string path, global::haxe.io.Bytes bytes) {
global::sys.io.FileOutput f = global::sys.io.File.write(path, new global::haxe.lang.Null<bool>(true, true));
f.writeBytes(bytes, 0, bytes.length);
f.close();
}
public static global::sys.io.FileInput read(string path, global::haxe.lang.Null<bool> binary) {
byte[] data = global::sys.FileSystem.ReadFileBytes(path);
if (( data == null )) {
throw ((global::System.Exception) (global::haxe.Exception.thrown(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Path \'", path), "\' doesn\'t exist"))) );
}
global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream(((byte[]) (data) ), ((bool) (false) ));
return new global::sys.io.FileInput(((global::System.IO.Stream) (stream) ));
}
public static global::sys.io.FileOutput write(string path, global::haxe.lang.Null<bool> binary) {
global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream();
return new global::sys.io.FileOutput(path, ((global::System.IO.Stream) (stream) ), true);
}
public static global::sys.io.FileOutput append(string path, global::haxe.lang.Null<bool> binary) {
byte[] data = global::sys.FileSystem.ReadFileBytes(path);
global::System.IO.MemoryStream stream = ( (( data == null )) ? (new global::System.IO.MemoryStream()) : (new global::System.IO.MemoryStream(((byte[]) (data) ), ((bool) (true) ))) );
stream.Seek(((long) (0) ), ((global::System.IO.SeekOrigin) (global::System.IO.SeekOrigin.End) ));
return new global::sys.io.FileOutput(path, ((global::System.IO.Stream) (stream) ), true);
}
public static global::sys.io.FileOutput update(string path, global::haxe.lang.Null<bool> binary) {
byte[] data = global::sys.FileSystem.ReadFileBytes(path);
global::System.IO.MemoryStream stream = ( (( data == null )) ? (new global::System.IO.MemoryStream()) : (new global::System.IO.MemoryStream(((byte[]) (data) ), ((bool) (true) ))) );
stream.Seek(((long) (0) ), ((global::System.IO.SeekOrigin) (global::System.IO.SeekOrigin.Begin) ));
return new global::sys.io.FileOutput(path, ((global::System.IO.Stream) (stream) ), true);
}
public static void copy(string srcPath, string dstPath) {
byte[] data = global::sys.FileSystem.ReadFileBytes(srcPath);
if (( data == null )) {
throw ((global::System.Exception) (global::haxe.Exception.thrown(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Path \'", srcPath), "\' doesn\'t exist"))) );
}
byte[] clone = new byte[( data as global::System.Array ).Length];
global::System.Array.Copy(((global::System.Array) (data) ), ((int) (0) ), ((global::System.Array) (clone) ), ((int) (0) ), ((int) (( data as global::System.Array ).Length) ));
global::sys.FileSystem.WriteFileBytes(dstPath, clone);
}
}
}