1 | import { u8aToU8a } from './toU8a.js';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export function u8aConcat(...list) {
|
20 | const count = list.length;
|
21 | const u8as = new Array(count);
|
22 | let length = 0;
|
23 | for (let i = 0; i < count; i++) {
|
24 | u8as[i] = u8aToU8a(list[i]);
|
25 | length += u8as[i].length;
|
26 | }
|
27 | return u8aConcatStrict(u8as, length);
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export function u8aConcatStrict(u8as, length = 0) {
|
34 | const count = u8as.length;
|
35 | let offset = 0;
|
36 | if (!length) {
|
37 | for (let i = 0; i < count; i++) {
|
38 | length += u8as[i].length;
|
39 | }
|
40 | }
|
41 | const result = new Uint8Array(length);
|
42 | for (let i = 0; i < count; i++) {
|
43 | result.set(u8as[i], offset);
|
44 | offset += u8as[i].length;
|
45 | }
|
46 | return result;
|
47 | }
|