Browse Source

[php] fix bytes count in FileInput.readBytes()

Alexander Kuzmenko 6 năm trước cách đây
mục cha
commit
a2f4d9f8c3

+ 5 - 0
std/php/Global.hx

@@ -1034,6 +1034,11 @@ extern class Global {
 	**/
 	**/
 	static function stream_select( read:NativeArray, write:NativeArray, except:NativeArray, tv_sec:Int, tv_usec:Int = 0 ) : Bool;
 	static function stream_select( read:NativeArray, write:NativeArray, except:NativeArray, tv_sec:Int, tv_usec:Int = 0 ) : Bool;
 
 
+	/**
+		@see http://php.net/manual/en/function.stream-get-contents.php
+	**/
+	static function stream_get_contents( handle:Resource, maxlength:Int = -1, offset:Int = -1 ) : EitherType<String,Bool>;
+
 	/**
 	/**
 		@see http://php.net/manual/en/function.stream-socket-shutdown.php
 		@see http://php.net/manual/en/function.stream-socket-shutdown.php
 	**/
 	**/

+ 3 - 3
std/php/_std/sys/io/FileInput.hx

@@ -47,11 +47,11 @@ class FileInput extends haxe.io.Input {
 	public override function readBytes( s : Bytes, p : Int, l : Int ) : Int {
 	public override function readBytes( s : Bytes, p : Int, l : Int ) : Int {
 		if(feof(__f)) throw new Eof();
 		if(feof(__f)) throw new Eof();
 		var r = fread(__f, l);
 		var r = fread(__f, l);
-		if(strlen(r) == 0) throw new Eof();
 		if(r == false) throw Custom('An error occurred');
 		if(r == false) throw Custom('An error occurred');
+		if(strlen(r) == 0) throw new Eof();
 		var b = Bytes.ofString(r);
 		var b = Bytes.ofString(r);
-		s.blit(p, b, 0, (r:String).length);
-		return (r:String).length;
+		s.blit(p, b, 0, strlen(r));
+		return strlen(r);
 	}
 	}
 
 
 	public override function close() : Void {
 	public override function close() : Void {