Преглед на файлове

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

Alexander Kuzmenko преди 6 години
родител
ревизия
a2f4d9f8c3
променени са 2 файла, в които са добавени 8 реда и са изтрити 3 реда
  1. 5 0
      std/php/Global.hx
  2. 3 3
      std/php/_std/sys/io/FileInput.hx

+ 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;
 
+	/**
+		@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
 	**/

+ 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 {
 		if(feof(__f)) throw new Eof();
 		var r = fread(__f, l);
-		if(strlen(r) == 0) throw new Eof();
 		if(r == false) throw Custom('An error occurred');
+		if(strlen(r) == 0) throw new Eof();
 		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 {