Created
June 14, 2016 07:27
-
-
Save timyhac/0459d9bd6a380e6c6e359cb9a583eb52 to your computer and use it in GitHub Desktop.
Javascript concatenate multiple buffers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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