Browse Source

[lua] fix File and FileInput for reading/writing bytes

Justin Donaldson 9 years ago
parent
commit
5b3641b6bb
2 changed files with 6 additions and 7 deletions
  1. 3 6
      std/lua/_std/sys/io/File.hx
  2. 3 1
      std/lua/_std/sys/io/FileInput.hx

+ 3 - 6
std/lua/_std/sys/io/File.hx

@@ -44,18 +44,15 @@ class File {
 	}
 
 	public static function getBytes( path : String ) : haxe.io.Bytes {
-		var f = read(path, true);
-		var ret = f.readAll();
-		f.close();
-		return ret;
+		return haxe.io.Bytes.ofString(getContent(path));
 	}
 
 	public static function read( path : String, binary : Bool = true ) : FileInput {
-		return new FileInput(Io.open(path,'r'));
+		return new FileInput(Io.open(path, binary ? 'rb' : 'r'));
 	}
 
 	public static function write( path : String, binary : Bool = true ) : FileOutput {
-		return new FileOutput(Io.open(path,'w'));
+		return new FileOutput(Io.open(path, binary ? 'wb' : 'w'));
 	}
 
 	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {

+ 3 - 1
std/lua/_std/sys/io/FileInput.hx

@@ -53,7 +53,9 @@ class FileInput extends haxe.io.Input {
 	}
 
 	override inline public function readByte() : Int {
-		return NativeStringTools.byte(f.read(1));
+		var byte = f.read(1);
+		if (byte == null) throw new haxe.io.Eof();
+		return NativeStringTools.byte(byte);
 	}
 
 	override inline public function close() : Void {