Created
October 28, 2014 12:06
-
-
Save tauzen/1f0671edbb5fc2049ba7 to your computer and use it in GitHub Desktop.
Joins multiple Uint8Arrays (or regular Arrays) passed as arguments into one combined Uint8Array.
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 joinUint8Arrays() { | |
var args = Array.prototype.slice.call(arguments); | |
var length = args.reduce(function(a, b) { return a + b.length; }, 0); | |
var out = new Uint8Array(length); | |
args.reduce(function(previousLen, buffer) { | |
out.set(buffer, previousLen); | |
return previousLen + buffer.length; | |
}, 0); | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment