(bytes: Uint8Array, maxLength = 200)
| 102 | * @returns ASCII string representation |
| 103 | */ |
| 104 | export function toAsciiString(bytes: Uint8Array, maxLength = 200) { |
| 105 | const slice = bytes.slice(0, maxLength); |
| 106 | |
| 107 | const ascii = Array.from(slice) |
| 108 | .map(b => (b >= 0x20 && b < 0x7f ? String.fromCharCode(b) : ".")) |
| 109 | .join(""); |
| 110 | |
| 111 | return bytes.length > maxLength ? `${ascii}...` : ascii; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Assert that two Uint8Arrays are equal. |
no test coverage detected