Skip to content

Instantly share code, notes, and snippets.

@EcksDy
EcksDy / concat-files-content.ts
Created May 6, 2021 15:42
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);
}