Browse Source

STD: Add length property to BytesInput

Mike Welsh 12 years ago
parent
commit
038d96e2ea
1 changed files with 15 additions and 1 deletions
  1. 15 1
      std/haxe/io/BytesInput.hx

+ 15 - 1
std/haxe/io/BytesInput.hx

@@ -26,10 +26,15 @@ class BytesInput extends Input {
 	#if !flash9
 	var pos : Int;
 	var len : Int;
+	var totlen : Int;
 	#end
 	
+	/** The current position in the stream in bytes. */
 	public var position(get,set) : Int;
 
+	/** The length of the stream in bytes. */
+	public var length(get,never) : Int;
+
 	public function new( b : Bytes, ?pos : Int, ?len : Int ) {
 		if( pos == null ) pos = 0;
 		if( len == null ) len = b.length - pos;
@@ -48,10 +53,11 @@ class BytesInput extends Input {
 		this.b = b.getData();
 		this.pos = pos;
 		this.len = len;
+		this.totlen = len;
 		#end
 	}
 	
-	function get_position() : Int {
+	inline function get_position() : Int {
 		#if flash9
 		return b.position;
 		#else
@@ -59,6 +65,14 @@ class BytesInput extends Input {
 		#end
 	}
 
+	inline function get_length() : Int {
+		#if flash9
+		return b.length;
+		#else
+		return totlen;
+		#end
+	}
+	
 	function set_position( p : Int ) : Int {
 		#if flash9
 		return b.position = p;