Kaynağa Gözat

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

Justin Donaldson 9 yıl önce
ebeveyn
işleme
8d671edd13
1 değiştirilmiş dosya ile 18 ekleme ve 0 silme
  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.Boot;
 import lua.Os;
+import haxe.io.Bytes;
+import haxe.io.Error;
+import haxe.io.Eof;
 
 class FileInput extends haxe.io.Input {
 	var f:FileHandle;
@@ -61,5 +64,20 @@ class FileInput extends haxe.io.Input {
 	override inline public function close() : Void {
 		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();
+	}
+
 
 }