浏览代码

[lua] add FileInput.readAll override as a temporary fix for Input issues

Justin Donaldson 9 年之前
父节点
当前提交
8d671edd13
共有 1 个文件被更改,包括 18 次插入0 次删除
  1. 18 0
      std/lua/_std/sys/io/FileInput.hx

+ 18 - 0
std/lua/_std/sys/io/FileInput.hx

@@ -26,6 +26,9 @@ import lua.Io;
 import lua.NativeStringTools;
 import lua.NativeStringTools;
 import lua.Boot;
 import lua.Boot;
 import lua.Os;
 import lua.Os;
+import haxe.io.Bytes;
+import haxe.io.Error;
+import haxe.io.Eof;
 
 
 class FileInput extends haxe.io.Input {
 class FileInput extends haxe.io.Input {
 	var f:FileHandle;
 	var f:FileHandle;
@@ -61,5 +64,20 @@ class FileInput extends haxe.io.Input {
 	override inline public function close() : Void {
 	override inline public function close() : Void {
 		f.close();
 		f.close();
 	}
 	}
+	override public function readAll( ?bufsize : Int ) : Bytes {
+		if( bufsize == null )
+			bufsize = (1 << 14); // 16 Ko
+		var buf = Bytes.alloc(bufsize);
+		var total = new haxe.io.BytesBuffer();
+		try {
+			while( true ) {
+				var len = readBytes(buf,0,bufsize);
+				if (len == 0) break;
+				total.addBytes(buf,0,len);
+			}
+		} catch( e : Eof ) { }
+		return total.getBytes();
+	}
+
 
 
 }
 }