(data: ArrayBuffer | Uint8Array | string)
| 33 | const textEncoder = new TextEncoder(); |
| 34 | |
| 35 | function toArrayBuffer(data: ArrayBuffer | Uint8Array | string): ArrayBuffer { |
| 36 | if (typeof data === "string") { |
| 37 | return textEncoder.encode(data).buffer as ArrayBuffer; |
| 38 | } |
| 39 | |
| 40 | if (data instanceof Uint8Array) { |
| 41 | return new Uint8Array(data).buffer; |
| 42 | } |
| 43 | |
| 44 | return data; |
| 45 | } |
| 46 | |
| 47 | function toHex(buffer: ArrayBuffer): string { |
| 48 | return Array.from(new Uint8Array(buffer), b => b.toString(16).padStart(2, "0")).join(""); |
no outgoing calls
no test coverage detected