Files
termos/src/util/concat.ts
T
ChaosMaker d0f8376244 - moved uint8array concat and split functions to their own files
- fixed an error in the cd command as a result of a previous improvement
2026-08-30 08:38:05 +02:00

27 lines
682 B
TypeScript

export function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {
const size = arrays.reduce((sum, arr) => sum + arr.length, 0);
const array = new Uint8Array(size);
let offset = 0;
for (const arr of arrays) {
array.set(arr, offset);
offset += arr.length;
}
return array;
}
export function splitUint8Array(data: Uint8Array, size: number): Uint8Array[] {
const nChunks: number = Math.ceil(data.length / size);
const chunks: Uint8Array[] = [];
for (let i = 0; i < nChunks; i++) {
const start = size * i;
const end = size * (i + 1);
chunks.push(data.subarray(start, end));
}
return chunks;
}