added fs abstrction

This commit is contained in:
Djeeberjr 2022-03-11 17:44:54 +01:00
parent e777736e6e
commit 7ff19b3ed5

View File

@ -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<String>{
return this.readLine(withTrailing);
}
public inline function readAll():Null<String>{
return this.readAll();
}
public inline function read(?count:Int = 1):Null<String>{
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<String>{
return this.readLine(withTrailing);
}
public inline function readAll():Null<String>{
return this.readAll();
}
public inline function read(count:Int):Null<String>{
return this.read(count);
}
public inline function readByte():Null<Int>{
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.
}