(data: ArrayBuffer | Uint8Array | string)
| 50 | * ``` |
| 51 | */ |
| 52 | export function encodeBase64(data: ArrayBuffer | Uint8Array | string): string { |
| 53 | if (typeof data === "string") { |
| 54 | data = new TextEncoder().encode(data) as Uint8Array_; |
| 55 | } else if (data instanceof ArrayBuffer) data = new Uint8Array(data).slice(); |
| 56 | else data = data.slice(); |
| 57 | const [output, i] = detach( |
| 58 | data as Uint8Array_, |
| 59 | calcSizeBase64((data as Uint8Array_).length), |
| 60 | ); |
| 61 | encode(output, i, 0, alphabet, padding); |
| 62 | return new TextDecoder().decode(output); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Decodes a base64-encoded string. |
no test coverage detected