Skip to content

Instantly share code, notes, and snippets.

@EcksDy
Created May 6, 2021 15:42
Show Gist options
  • Save EcksDy/d3483f3cdf06a16b6b5a8ce4dfe458de to your computer and use it in GitHub Desktop.
Save EcksDy/d3483f3cdf06a16b6b5a8ce4dfe458de to your computer and use it in GitHub Desktop.
Function to concat multiple Uint8Array's
function concatFilesContent(contents: Uint8Array[]) {
// Could've returned [...acc, ...curr] in the reducer callback, it would look nice and clean,
// but it would made a copy of the acc, which is less performant
const newContent = contents.reduce((acc: number[], curr: Uint8Array) => {
acc.push(...curr);
return acc;
}, []);
return new Uint8Array(newContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment