diff --git a/src/kernel/fs/FileHandler.hx b/src/kernel/fs/FileHandler.hx new file mode 100644 index 0000000..244b4d3 --- /dev/null +++ b/src/kernel/fs/FileHandler.hx @@ -0,0 +1,116 @@ +package kernel.fs; + +import cc.FileSystem.FileHandle; + +using tink.CoreApi; + +abstract ReadHandle(FileHandle) from FileHandle { + + public inline function new(handle:FileHandle) { + this = handle; + } + + public inline function readLine(?withTrailing:Bool = false):Null{ + return this.readLine(withTrailing); + } + + public inline function readAll():Null{ + return this.readAll(); + } + + public inline function read(?count:Int = 1):Null{ + return this.read(count); + } + + public inline function close():Void{ + this.close(); + } +} + +abstract WriteHandle(FileHandle) from FileHandle { + + public inline function new(handle:FileHandle) { + this = handle; + } + + public inline function write(data:String):Void{ + this.write(data); + } + + public inline function writeLine(data:String):Void{ + this.writeLine(data); + } + + public inline function flush():Void{ + this.flush(); + } + + public inline function close():Void{ + this.close(); + } +} + +abstract ReadBinaryHandle(FileHandle) from FileHandle { + + public inline function new(handle:FileHandle) { + this = handle; + } + + public inline function readLine(?withTrailing:Bool = false):Null{ + return this.readLine(withTrailing); + } + + public inline function readAll():Null{ + return this.readAll(); + } + + public inline function read(count:Int):Null{ + return this.read(count); + } + + public inline function readByte():Null{ + return this.read(); + } + + public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{ + this.seek(whence,offset); + } + + public inline function close():Void{ + this.close(); + } +} + +abstract WriteBinaryHandle(FileHandle) from FileHandle { + + public inline function new(handle:FileHandle) { + this = handle; + } + + public inline function write(data: String):Void{ + this.write(data); + } + + // TODO + public inline function writeByte(data: Int):Void{ + // this.write(data); + } + + public inline function flush():Void{ + this.flush(); + } + + public inline function close():Void{ + this.close(); + } + + public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{ + this.seek(whence,offset); + } +} + +@:enum abstract BinarySeekWhence(String) to String { + var Set = "set"; // Relative to the beginning of the file. + var Current = "cur"; // Relative to the current position. This is the default. + var End = "end"; // Relative to the end of the file. +}