Skip to content

Instantly share code, notes, and snippets.

@tauzen
Created October 28, 2014 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tauzen/1f0671edbb5fc2049ba7 to your computer and use it in GitHub Desktop.
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.
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