2
0
Эх сурвалжийг харах

STD: Add length property to BytesBuffer, BytesOutput

Mike Welsh 12 жил өмнө
parent
commit
99027dd753

+ 15 - 0
std/haxe/io/BytesBuffer.hx

@@ -39,6 +39,9 @@ class BytesBuffer {
 	var b : Array<Int>;
 	#end
 
+	/** The length of the buffer in bytes. **/
+	public var length(get,never) : Int;
+
 	public function new() {
 		#if neko
 		b = untyped StringBuf.__make();
@@ -57,6 +60,18 @@ class BytesBuffer {
 		#end
 	}
 
+	inline function get_length() : Int {
+		#if neko
+		return untyped __dollar__ssize( StringBuf.__to_string(b) );
+		#elseif cs
+		return haxe.Int64.toInt( b.Length );
+		#elseif java
+		return b.size();
+		#else
+		return b.length;
+		#end
+	}
+
 	public inline function addByte( byte : Int ) {
 		#if neko
 		untyped StringBuf.__add_char(b,byte);

+ 7 - 0
std/haxe/io/BytesOutput.hx

@@ -29,6 +29,9 @@ class BytesOutput extends Output {
 	var b : BytesBuffer;
 	#end
 
+	/** The length of the stream in bytes. **/
+	public var length(get,never) : Int;
+
 	public function new() {
 		#if flash9
 		b = new flash.utils.ByteArray();
@@ -38,6 +41,10 @@ class BytesOutput extends Output {
 		#end
 	}
 
+	inline function get_length() : Int {
+		return b.length;
+	}
+
 	override function writeByte(c) {
 		#if flash9
 		b.writeByte(c);