• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LukaJCB / ts-mls / 19395039460

15 Nov 2025 08:17PM UTC coverage: 93.865% (-0.1%) from 94.013%
19395039460

Pull #140

github

web-flow
Merge 2d4f3e587 into 26cb8686d
Pull Request #140: Optimize byte buffer allocations

1128 of 1258 branches covered (89.67%)

Branch coverage included in aggregate %.

57 of 67 new or added lines in 7 files covered. (85.07%)

2 existing lines in 1 file now uncovered.

6430 of 6794 relevant lines covered (94.64%)

46061.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.82
/src/util/byteArray.ts
1
export function copyToBuffer(b: Uint8Array): ArrayBuffer {
1✔
UNCOV
2
  return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength) as ArrayBuffer
×
UNCOV
3
}
×
4

5
export function bytesToArrayBuffer(b: Uint8Array): ArrayBuffer {
1✔
6
  if (b.buffer instanceof ArrayBuffer) {
975,895✔
7
    if (b.byteOffset === 0 && b.byteLength === b.buffer.byteLength) {
975,895✔
8
      return b.buffer
960,545✔
9
    }
960,545✔
10
    return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength)
15,350✔
11
  } else {
945,110!
NEW
12
    const ab = new ArrayBuffer(b.byteLength)
×
NEW
13
    const arr = new Uint8Array(ab)
×
NEW
14
    arr.set(b, 0)
×
NEW
15
    return ab
×
NEW
16
  }
×
17
}
975,895✔
18

19
export function toBufferSource(b: Uint8Array): BufferSource {
1✔
20
  if (b.buffer instanceof ArrayBuffer) return b as Uint8Array<ArrayBuffer>
336,851!
NEW
21
  const ab = new ArrayBuffer(b.byteLength)
×
NEW
22
  const arr = new Uint8Array(ab)
×
NEW
23
  arr.set(b, 0)
×
NEW
24
  return ab
×
NEW
25
}
×
26

27
export function bytesToBase64(bytes: Uint8Array): string {
1✔
28
  if (typeof Buffer !== "undefined") {
8,958✔
29
    return Buffer.from(bytes).toString("base64")
8,957✔
30
  } else {
8,958✔
31
    let binary = ""
1✔
32
    bytes.forEach((b) => (binary += String.fromCharCode(b)))
1✔
33
    return globalThis.btoa(binary)
1✔
34
  }
1✔
35
}
8,958✔
36

37
export function base64ToBytes(base64: string): Uint8Array {
1✔
38
  if (typeof Buffer !== "undefined") {
103✔
39
    return Uint8Array.from(Buffer.from(base64, "base64"))
102✔
40
  } else {
103✔
41
    const binary = globalThis.atob(base64)
1✔
42
    const bytes = new Uint8Array(binary.length)
1✔
43
    for (let i = 0; i < binary.length; i++) {
1✔
44
      bytes[i] = binary.charCodeAt(i)
10✔
45
    }
10✔
46
    return bytes
1✔
47
  }
1✔
48
}
103✔
49

50
export function concatUint8Arrays(a: Uint8Array, b: Uint8Array): Uint8Array {
1✔
51
  const result = new Uint8Array(a.length + b.length)
46,464✔
52
  result.set(a, 0)
46,464✔
53
  result.set(b, a.length)
46,464✔
54
  return result
46,464✔
55
}
46,464✔
56

57
export function concat3Uint8Arrays(a: Uint8Array, b: Uint8Array, c: Uint8Array): Uint8Array {
1✔
58
  const result = new Uint8Array(a.length + b.length + c.length)
116,253✔
59
  result.set(a, 0)
116,253✔
60
  result.set(b, a.length)
116,253✔
61
  result.set(c, a.length + b.length)
116,253✔
62
  return result
116,253✔
63
}
116,253✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc