Created
May 6, 2021 15:42
-
-
Save EcksDy/d3483f3cdf06a16b6b5a8ce4dfe458de to your computer and use it in GitHub Desktop.
Function to concat multiple Uint8Array's
This file contains 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 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