Browse Source

inversed read/readBytes and write/writeBytes

Nicolas Cannasse 19 years ago
parent
commit
4e97457379

+ 9 - 9
std/haxe/Http.hx

@@ -279,9 +279,9 @@ class Http {
 		var s = neko.Lib.makeString(4);
 		sock.setTimeout(10); // 10 seconds
 		while( true ) {
-			var p = sock.input.read(s,0,k);
+			var p = sock.input.readBytes(s,0,k);
 			while( p != k )
-				p += sock.input.read(s,p,k - p);
+				p += sock.input.readBytes(s,p,k - p);
 			b.addSub(s,0,k);
 			switch( k ) {
 			case 1:
@@ -374,18 +374,18 @@ class Http {
 		if( size == null ) {
 			sock.shutdown(false,true);
 			while( true ) {
-				var len = sock.input.read(buf,0,bufsize);
+				var len = sock.input.readBytes(buf,0,bufsize);
 				if( len == 0 )
 					break;
 				if( chunked ) {
 					if( !readChunk(chunk_re,api,buf,len) )
 						break;
 				} else
-					api.write(buf,0,len);
+					api.writeBytes(buf,0,len);
 			}
 		} else {
 			while( size > 0 ) {
-				var len = sock.input.read(buf,0,if( size > bufsize ) bufsize else size);
+				var len = sock.input.readBytes(buf,0,if( size > bufsize ) bufsize else size);
 				if( len == 0 ) {
 					onError("Transfert aborted");
 					return;
@@ -394,7 +394,7 @@ class Http {
 					if( !readChunk(chunk_re,api,buf,len) )
 						break;
 				} else
-					api.write(buf,0,len);
+					api.writeBytes(buf,0,len);
 				size -= len;
 			}
 		}
@@ -431,13 +431,13 @@ class Http {
 		}
 		if( chunk_size > len ) {
 			chunk_size -= len;
-			api.write(buf,0,len);
+			api.writeBytes(buf,0,len);
 			return true;
 		}
 		var end = chunk_size + 2;
 		if( len >= end ) {
 			if( chunk_size > 0 )
-				api.write(buf,0,chunk_size);
+				api.writeBytes(buf,0,chunk_size);
 			len -= end;
 			chunk_size = null;
 			if( len == 0 )
@@ -445,7 +445,7 @@ class Http {
 			return readChunk(chunk_re,api,buf.substr(end,len),len);
 		}
 		if( chunk_size > 0 )
-			api.write(buf,0,chunk_size);
+			api.writeBytes(buf,0,chunk_size);
 		chunk_size -= len;
 		return true;
 	}

+ 2 - 0
std/haxe/ImportAll.hx

@@ -501,6 +501,8 @@ import neko.io.File;
 import neko.io.FileInput;
 import neko.io.FileOutput;
 import neko.io.Input;
+import neko.io.Logger;
+import neko.io.Multiple;
 import neko.io.Output;
 import neko.io.Socket;
 import neko.io.SocketInput;

+ 1 - 1
std/haxe/remoting/SocketBuffer.hx

@@ -65,7 +65,7 @@ class SocketBuffer {
 
 	public function read() {
 		var buflen = buffer.length;
-		var len = try sock.input.read(buffer,bufpos,buflen-bufpos) catch( e : Dynamic ) { if( e == neko.io.Error.Blocked ) return; 0; };
+		var len = try sock.input.readBytes(buffer,bufpos,buflen-bufpos) catch( e : Dynamic ) { if( e == neko.io.Error.Blocked ) return; 0; };
 		if( len == 0 )
 			throw ReadError;
 		lastread = neko.Sys.time();

+ 1 - 1
std/haxe/remoting/SocketConnection.hx

@@ -123,7 +123,7 @@ class SocketConnection extends AsyncConnection {
 		var s : neko.io.Socket = __data;
 		s.output.writeChar(c1);
 		s.output.writeChar(c2);
-		s.output.writeBytes(msg);
+		s.output.write(msg);
 		s.output.writeChar(0);
 		#else flash
 		var s : flash.XMLSocket = __data;

+ 1 - 1
std/neko/io/FileInput.hx

@@ -47,7 +47,7 @@ class FileInput extends Input {
 		}
 	}
 
-	public override function read( s : String, p : Int, l : Int ) : Int {
+	public override function readBytes( s : String, p : Int, l : Int ) : Int {
 		return try {
 			file_read(__f,untyped s.__s,p,l);
 		} catch( e : Dynamic ) {

+ 1 - 1
std/neko/io/FileOutput.hx

@@ -44,7 +44,7 @@ class FileOutput extends Output {
 		}
 	}
 
-	public override function write( s : String, p : Int, l : Int ) : Int {
+	public override function writeBytes( s : String, p : Int, l : Int ) : Int {
 		return try {
 			file_write(__f,untyped s.__s,p,l);
 		} catch( e : Dynamic ) {

+ 11 - 10
std/neko/io/Input.hx

@@ -35,7 +35,7 @@ class Input {
 		return throw "Not implemented";
 	}
 
-	public function read( s : String, p : Int, len : Int ) : Int {
+	public function readBytes( s : String, p : Int, len : Int ) : Int {
 		var k = len;
 		while( k > 0 ) {
 			var c = readChar();
@@ -47,8 +47,9 @@ class Input {
 	}
 
 	public function close() {
-		read = function(_,_,_) { return throw Error.Closed; };
+		readBytes = function(_,_,_) { return throw Error.Closed; };
 		readChar = function() { return throw Error.Closed; };
+		skip = function(_) { throw Error.Closed; };
 		close = function() { };
 	}
 
@@ -62,7 +63,7 @@ class Input {
 		var total = new StringBuf();
 		try {
 			while( true ) {
-				var len = read(buf,0,bufsize);
+				var len = readBytes(buf,0,bufsize);
 				if( len == 0 )
 					throw Error.Blocked;
 				total.addSub(buf,0,len);
@@ -74,11 +75,11 @@ class Input {
 		return total.toString();
 	}
 
-	public function readBytes( nbytes : Int ) : String {
+	public function read( nbytes : Int ) : String {
 		var s = neko.Lib.makeString(nbytes);
 		var p = 0;
 		while( nbytes > 0 ) {
-			var k = read(s,p,nbytes);
+			var k = readBytes(s,p,nbytes);
 			if( k == 0 ) throw Error.Blocked;
 			p += k;
 			nbytes -= k;
@@ -101,23 +102,23 @@ class Input {
 	}
 
 	public function skip( nbytes : Int ) {
-		readBytes(nbytes);
+		read(nbytes);
 	}
 
 	public function readFloat() {
-		return _float_of_bytes(untyped readBytes(4).__s,false);
+		return _float_of_bytes(untyped read(4).__s,false);
 	}
 
 	public function readFloatB() {
-		return _float_of_bytes(untyped readBytes(4).__s,true);
+		return _float_of_bytes(untyped read(4).__s,true);
 	}
 
 	public function readDouble() {
-		return _double_of_bytes(untyped readBytes(8).__s,false);
+		return _double_of_bytes(untyped read(8).__s,false);
 	}
 
 	public function readDoubleB() {
-		return _double_of_bytes(untyped readBytes(8).__s,true);
+		return _double_of_bytes(untyped read(8).__s,true);
 	}
 
 	public function readInt8() {

+ 3 - 3
std/neko/io/Logger.hx

@@ -50,10 +50,10 @@ class Logger extends Input {
 		return c;
 	}
 
-	public override function read(buf,pos,len) {
-		var n = input.read(buf,pos,len);
+	public override function readBytes(buf,pos,len) {
+		var n = input.readBytes(buf,pos,len);
 		logString(buf.substr(pos,n));
-		if( output != null ) output.write(buf,pos,n);
+		if( output != null ) output.writeBytes(buf,pos,n);
 		if( autoFlush ) output.flush();
 		return n;
 	}

+ 8 - 8
std/neko/io/Output.hx

@@ -36,7 +36,7 @@ class Output {
 		throw "Not implemented";
 	}
 
-	public function write( s : String, p : Int, len : Int ) : Int {
+	public function writeBytes( s : String, p : Int, len : Int ) : Int {
 		var k = len;
 		while( k > 0 ) {
 			writeChar(untyped __dollar__sget(s.__s,p));
@@ -50,7 +50,7 @@ class Output {
 	}
 
 	public function close() {
-		write = function(_,_,_) { return throw Error.Closed; };
+		writeBytes = function(_,_,_) { return throw Error.Closed; };
 		writeChar = function(_) { throw Error.Closed; };
 		flush = function() { throw Error.Closed; };
 		close = function() { };
@@ -58,11 +58,11 @@ class Output {
 
 	/* ------------------ API ------------------ */
 
-	public function writeBytes( s : String ) : Void {
+	public function write( s : String ) : Void {
 		var l = s.length;
 		var p = 0;
 		while( l > 0 ) {
-			var k = write(s,p,l);
+			var k = writeBytes(s,p,l);
 			if( k == 0 ) throw Error.Blocked;
 			p += k;
 			l -= k;
@@ -70,19 +70,19 @@ class Output {
 	}
 
 	public function writeFloat( c : Float ) {
-		writeBytes(new String(_float_bytes(c,false)));
+		write(new String(_float_bytes(c,false)));
 	}
 
 	public function writeFloatB( c : Float ) {
-		writeBytes(new String(_float_bytes(c,true)));
+		write(new String(_float_bytes(c,true)));
 	}
 
 	public function writeDouble( c : Float ) {
-		writeBytes(new String(_double_bytes(c,false)));
+		write(new String(_double_bytes(c,false)));
 	}
 
 	public function writeDoubleB( c : Float ) {
-		writeBytes(new String(_double_bytes(c,true)));
+		write(new String(_double_bytes(c,true)));
 	}
 
 	public function writeInt8( c : Int ) {

+ 1 - 1
std/neko/io/SocketInput.hx

@@ -44,7 +44,7 @@ class SocketInput extends Input {
 		}
 	}
 
-	public override function read( buf : String, pos : Int, len : Int ) : Int {
+	public override function readBytes( buf : String, pos : Int, len : Int ) : Int {
 		return try {
 			socket_recv(__s,untyped buf.__s,pos,len);
 		} catch( e : Dynamic ) {

+ 1 - 1
std/neko/io/SocketOutput.hx

@@ -44,7 +44,7 @@ class SocketOutput extends Output {
 		}
 	}
 
-	public override function write( buf : String, pos : Int, len : Int) : Int {
+	public override function writeBytes( buf : String, pos : Int, len : Int) : Int {
 		return try {
 			socket_send(__s, untyped buffer.__s, pos, len);
 		} catch( e : Dynamic ) {

+ 1 - 1
std/neko/io/StringInput.hx

@@ -47,7 +47,7 @@ class StringInput extends Input {
 		return c;
 	}
 
-	public override function read( buf : String, bpos, blen ) : Int {
+	public override function readBytes( buf : String, bpos, blen ) : Int {
 		if( len == 0 && blen > 0 )
 			throw Error.Eof;
 		if( len < blen )

+ 1 - 1
std/neko/io/StringOutput.hx

@@ -36,7 +36,7 @@ class StringOutput extends Output {
 		b.addChar(c);
 	}
 
-	public override function write( buf, bpos, blen ) : Int {
+	public override function writeBytes( buf, bpos, blen ) : Int {
 		b.addSub(buf,bpos,blen);
 		return blen;
 	}

+ 2 - 2
std/neko/zip/File.hx

@@ -60,12 +60,12 @@ class File {
 			data.skip(2);
 			var elen = data.readInt16();
 			data.skip(2);
-			var fname = data.readBytes(fnamelen);
+			var fname = data.read(fnamelen);
 			data.skip(elen);
 			l.add({
 				fileName : fname,
 				fileSize : usize,
-				compressedData : data.readBytes(csize)
+				compressedData : data.read(csize)
 			});
 		}
 		return l;

+ 1 - 1
std/tools/haxedoc/Main.hx

@@ -636,7 +636,7 @@ class DocView {
 		Url.buffer = new StringBuf();
 		displayHtml(html,clname);
 		var f = neko.io.File.write(file,false);
-		f.writeBytes(Url.buffer.toString());
+		f.write(Url.buffer.toString());
 		f.close();
 		neko.Lib.print(".");
 	}