Suite of AT Protocol TypeScript libraries built on web standards
1import { allocUnsafe } from "./alloc.ts";
2import { asUint8Array } from "./util.ts";
3
4/**
5 * Returns a new Uint8Array created by concatenating the passed Uint8Arrays
6 */
7export function concat(arrays: Uint8Array[], length?: number): Uint8Array {
8 if (length == null) {
9 length = arrays.reduce((acc, curr) => acc + curr.length, 0);
10 }
11
12 const output = allocUnsafe(length);
13 let offset = 0;
14
15 for (const arr of arrays) {
16 output.set(arr, offset);
17 offset += arr.length;
18 }
19
20 return asUint8Array(output);
21}