Compare commits
2 Commits
de35f34173
...
7ff19b3ed5
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ff19b3ed5 | |||
| e777736e6e |
102
src/kernel/fs/FS.hx
Normal file
102
src/kernel/fs/FS.hx
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
116
src/kernel/fs/FileHandler.hx
Normal file
116
src/kernel/fs/FileHandler.hx
Normal 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.
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user