Skip to content

Commit

Permalink
fill in more of sys file externs for AIR
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Sep 12, 2023
1 parent 0b87e1a commit 7979a99
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
38 changes: 29 additions & 9 deletions externs/air/sys/FileSystem.hx
Original file line number Diff line number Diff line change
@@ -1,44 +1,64 @@
package sys;

import flash.filesystem.File in FlashFile;

@:dce
@:coreApi
class FileSystem
{
public static function exists(path:String):Bool
{
return false;
return new FlashFile(path).exists;
}

public static function rename(path:String, newPath:String):Void {}
public static function rename(path:String, newPath:String):Void
{
new FlashFile(path).moveTo(new FlashFile(newPath));
}

public static function stat(path:String):sys.FileStat
{
openfl.Lib.notImplemented();
return null;
}

public static function fullPath(relPath:String):String
{
return null;
var flashFile = new FlashFile(relPath);
flashFile.canonicalize();
return flashFile.nativePath;
}

public static function absolutePath(relPath:String):String
{
return null;
return new FlashFile(relPath).nativePath;
}

public static function isDirectory(path:String):Bool
{
return false;
return new FlashFile(path).isDirectory;
}

public static function createDirectory(path:String):Void {}
public static function createDirectory(path:String):Void
{
new FlashFile(path).createDirectory();
}

public static function deleteFile(path:String):Void {}
public static function deleteFile(path:String):Void
{
new FlashFile(path).deleteFile();
}

public static function deleteDirectory(path:String):Void {}
public static function deleteDirectory(path:String):Void
{
new FlashFile(path).deleteDirectory(false);
}

public static function readDirectory(path:String):Array<String>
{
return null;
return new FlashFile(path).getDirectoryListing().map(function(f:FlashFile):String
{
return f.name;
});
}
}
38 changes: 34 additions & 4 deletions externs/air/sys/io/File.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sys.io;

import openfl.utils.ByteArray;
import flash.filesystem.File in FlashFile;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
Expand All @@ -18,34 +19,63 @@ class File
return content;
}

public static function saveContent(path:String, content:String):Void {}
public static function saveContent(path:String, content:String):Void
{
var file = new FlashFile(path);
var stream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes(content);
stream.close();
}

public static function getBytes(path:String):haxe.io.Bytes
{
return null;
var file = new FlashFile(path);
var stream = new FileStream();
stream.open(file, FileMode.READ);
var byteArray = new ByteArray();
stream.readBytes(byteArray, 0, stream.bytesAvailable);
stream.close();
var bytes:haxe.io.Bytes = byteArray;
return bytes;
}

public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void {}
public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void
{
var byteArray:ByteArray = bytes;
var file = new FlashFile(path);
var stream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeBytes(byteArray);
stream.close();
}

public static function read(path:String, binary:Bool = true):FileInput
{
openfl.Lib.notImplemented();
return null;
}

public static function write(path:String, binary:Bool = true):FileOutput
{
openfl.Lib.notImplemented();
return null;
}

public static function append(path:String, binary:Bool = true):FileOutput
{
openfl.Lib.notImplemented();
return null;
}

public static function update(path:String, binary:Bool = true):FileOutput
{
openfl.Lib.notImplemented();
return null;
}

public static function copy(srcPath:String, dstPath:String):Void {}
public static function copy(srcPath:String, dstPath:String):Void
{
new FlashFile(srcPath).copyTo(new FlashFile(dstPath));
}
}

0 comments on commit 7979a99

Please sign in to comment.