Browse Source

added fullBytes methods.

Nicolas Cannasse 19 năm trước cách đây
mục cha
commit
0a165e65ce
2 tập tin đã thay đổi với 20 bổ sung4 xóa
  1. 8 0
      std/neko/io/Input.hx
  2. 12 4
      std/neko/io/Output.hx

+ 8 - 0
std/neko/io/Input.hx

@@ -72,6 +72,14 @@ class Input {
 		return total.toString();
 	}
 
+	public function readFullBytes( s : String, pos : Int, len : Int ) {
+		while( len > 0 ) {
+			var k = readBytes(s,pos,len);
+			pos += k;
+			len -= k;
+		}
+	}
+
 	public function read( nbytes : Int ) : String {
 		var s = neko.Lib.makeString(nbytes);
 		var p = 0;

+ 12 - 4
std/neko/io/Output.hx

@@ -69,6 +69,14 @@ class Output {
 		}
 	}
 
+	public function writeFullBytes( s : String, pos : Int, len : Int ) {
+		while( len > 0 ) {
+			var k = writeBytes(s,pos,len);
+			pos += k;
+			len -= k;
+		}
+	}
+
 	public function writeFloat( c : Float ) {
 		write(new String(_float_bytes(c,false)));
 	}
@@ -109,14 +117,14 @@ class Output {
 		writeChar(x >> 8);
 		writeChar(x & 0xFF);
 	}
-	
+
 	public function writeUInt24B( x : Int ) {
 		if( x < 0 || x > 0xFFFFFF ) throw Error.Overflow;
 		writeChar(x >> 16);
 		writeChar((x >> 8) & 0xFF);
 		writeChar(x & 0xFF);
 	}
-	
+
 	public function writeInt16( x : Int ) {
 		if( x < -0x7FFF || x > 0x7FFF ) throw Error.Overflow;
 		if( x < 0 )
@@ -133,7 +141,7 @@ class Output {
 	**/
 	public function prepare( nbytes : Int ) {
 	}
-	
+
 	public function writeInput( i : Input, ?bufsize : Int ) {
 		if( bufsize == null )
 			bufsize = 4096;
@@ -152,7 +160,7 @@ class Output {
 					len -= k;
 				}
 			}
-		} catch( e : Eof ) {			
+		} catch( e : Eof ) {
 		}
 	}