Skip to content

Instantly share code, notes, and snippets.

@timyhac
Created June 14, 2016 07:27
Show Gist options
  • Save timyhac/0459d9bd6a380e6c6e359cb9a583eb52 to your computer and use it in GitHub Desktop.
Save timyhac/0459d9bd6a380e6c6e359cb9a583eb52 to your computer and use it in GitHub Desktop.
Javascript concatenate multiple buffers
function concatBuffers() {
var totalSize = 0;
for( let arg of arguments){
totalSize += arg.byteLength;
}
var tmp = new Uint8Array( totalSize );
var runningTotalSize = 0;
for( let arg of arguments){
tmp.set( new Uint8Array( arg ), runningTotalSize );
runningTotalSize += arg.byteLength;
}
return tmp;
}
concatBuffers(new Uint8Array([0xe6]), new Uint8Array([0xe9]), new Uint8Array([0xa6]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment