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

LukaJCB / ts-mls / 21789450455

08 Feb 2026 12:33AM UTC coverage: 96.205% (-0.04%) from 96.24%
21789450455

push

github

web-flow
Update docs link (#276)

408 of 411 branches covered (99.27%)

Branch coverage included in aggregate %.

2330 of 2435 relevant lines covered (95.69%)

70291.87 hits per line

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

78.38
/src/util/byteArray.ts
1
/** @public */
2
export function bytesToArrayBuffer(b: Uint8Array): ArrayBuffer {
3
  if (b.buffer instanceof ArrayBuffer) {
628,408✔
4
    if (b.byteOffset === 0 && b.byteLength === b.buffer.byteLength) {
628,406✔
5
      return b.buffer
612,888✔
6
    }
7
    return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength)
15,518✔
8
  } else {
9
    const ab = new ArrayBuffer(b.byteLength)
2✔
10
    const arr = new Uint8Array(ab)
2✔
11
    arr.set(b, 0)
2✔
12
    return ab
2✔
13
  }
14
}
15
/** @public */
16
export function toBufferSource(b: Uint8Array): BufferSource {
17
  if (b.buffer instanceof ArrayBuffer) return b as Uint8Array<ArrayBuffer>
405,600✔
18
  const ab = new ArrayBuffer(b.byteLength)
2✔
19
  const arr = new Uint8Array(ab)
2✔
20
  arr.set(b, 0)
2✔
21
  return ab
2✔
22
}
23

24
/** @public */
25
export function bytesToBase64(bytes: Uint8Array): string {
26
  if (typeof Buffer !== "undefined") {
124,202✔
27
    return Buffer.from(bytes).toString("base64")
124,202✔
28
  } else {
29
    let binary = ""
×
30
    bytes.forEach((b) => (binary += String.fromCharCode(b)))
×
31
    return globalThis.btoa(binary)
×
32
  }
33
}
34

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

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

56
/** @public */
57
export function zeroOutUint8Array(buf: Uint8Array): void {
58
  crypto.getRandomValues(buf)
12,898✔
59
  for (let i = 0; i < buf.length; i++) {
12,898✔
60
    buf[i]! ^= buf[i]!
729,824✔
61
  }
62
}
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