Skip to content

Instantly share code, notes, and snippets.

@smallnewer
Created September 12, 2013 02:48
Show Gist options
  • Save smallnewer/6532574 to your computer and use it in GitHub Desktop.
Save smallnewer/6532574 to your computer and use it in GitHub Desktop.
链接两个buffer,类似数组的concat操作。实际操作的是两个Uint8Array。
/**
* Appends two ArrayBuffers into a new one.
*
* @param {ArrayBuffer} buffer1 The first buffer.
* @param {ArrayBuffer} buffer2 The second buffer.
*/
function appendBuffer(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set( new Uint8Array(buffer1), 0);
tmp.set( new Uint8Array(buffer2), buffer1.byteLength);
return tmp;
}
// 创建一个新的全局对象,保存buffer
var buffer = new Uint8Array();
// 将新的buffer插入到之前的buffer上
buffer = appendBuffer(buffer,newbuf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment