added fs abstrction

This commit is contained in:
Djeeberjr 2022-03-11 17:44:39 +01:00
parent de35f34173
commit e777736e6e

102
src/kernel/fs/FS.hx Normal file
View File

@ -0,0 +1,102 @@
package kernel.fs;
import kernel.fs.FileHandler.WriteBinaryHandle;
import kernel.fs.FileHandler.ReadBinaryHandle;
import kernel.fs.FileHandler.WriteHandle;
import kernel.fs.FileHandler.ReadHandle;
import cc.FileSystem;
using lua.Table;
/**
Wrapper to interact with the filesystem.
**/
class FS {
public static inline function list(path: String):Array<String> {
return FileSystem.list(path).toArray();
}
public static inline function combine(base: String, part: String): String {
return FileSystem.combine(base,part);
}
public static inline function getName(path: String): String {
return FileSystem.getName(path);
}
public static inline function getDir(path: String): String {
return FileSystem.getDir(path);
}
public static inline function getSize(path: String):Int {
return FileSystem.getSize(path);
}
public static inline function exists(path: String):Bool {
return FileSystem.exists(path);
}
public static inline function isDir(path: String): Bool {
return FileSystem.isDir(path);
}
public static inline function isReadOnly(path: String):Bool {
return FileSystem.isReadOnly(path);
}
public static inline function makeDir(path: String):Void {
FileSystem.makeDir(path);
}
public static inline function move(src:String,dest:String):Void {
FileSystem.move(src,dest);
}
public static inline function copy(src:String,dest:String):Void {
FileSystem.copy(src,dest);
}
public static inline function delete(path: String):Void {
FileSystem.delete(path);
}
public static inline function openRead(path:String): ReadHandle{
return FileSystem.open(path,Read);
}
public static inline function openWrite(path: String): WriteHandle {
return FileSystem.open(path,Write);
}
public static inline function openAppend(path: String): WriteHandle {
return FileSystem.open(path,Append);
}
public static inline function openReadBinary(path:String): ReadBinaryHandle {
return FileSystem.open(path,BinaryRead);
}
public static inline function openWriteBinary(path: String): WriteBinaryHandle {
return FileSystem.open(path,BinaryWrite);
}
public static inline function openAppendBinary(path: String): WriteBinaryHandle {
return FileSystem.open(path,BinaryAppend);
}
public static inline function find(pattern: String):Array<String> {
return FileSystem.find(pattern).toArray();
}
public static inline function getFreeSpace(path:String):Int {
return FileSystem.getFreeSpace(path);
}
public static inline function getCapacity(path:String):Int {
return FileSystem.getCapacity(path);
}
public static inline function attributes(path: String):FileAttributes {
return FileSystem.attributes(path);
}
}