浏览代码

fixed some specific cases with empty buffer

Nicolas Cannasse 8 年之前
父节点
当前提交
96693229b0
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      std/js/_std/haxe/io/BytesBuffer.hx

+ 4 - 1
std/js/_std/haxe/io/BytesBuffer.hx

@@ -34,7 +34,6 @@ class BytesBuffer {
 	public function new() {
 		pos = 0;
 		size = 0;
-		grow(0);
 	}
 
 	inline function get_length() : Int {
@@ -48,6 +47,7 @@ class BytesBuffer {
 
 	public function add( src : Bytes ) {
 		if( pos + src.length > size ) grow(src.length);
+		if( size == 0 ) return;
 		var sub = new js.html.Uint8Array(@:privateAccess src.b.buffer, @:privateAccess src.b.byteOffset, src.length);
 		u8.set(sub, pos);
 		pos += src.length;
@@ -85,6 +85,7 @@ class BytesBuffer {
 	public function addBytes( src : Bytes, pos : Int, len : Int ) {
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;
 		if( this.pos + len > size ) grow(len);
+		if( size == 0 ) return;
 		var sub = new js.html.Uint8Array(@:privateAccess src.b.buffer, @:privateAccess src.b.byteOffset + pos, len);
 		u8.set(sub, this.pos);
 		this.pos += len;
@@ -106,6 +107,8 @@ class BytesBuffer {
 	}
 
 	public function getBytes() : Bytes @:privateAccess {
+		if( size == 0 )
+			return haxe.io.Bytes.alloc(0);
 		var b = new Bytes(buffer);
 		b.length = pos;
 		return b;