- moved uint8array concat and split functions to their own files
- fixed an error in the cd command as a result of a previous improvement
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user