(
input: string | Uint8Array_ | ArrayBuffer,
output: Uint8Array_,
options: Base32Options = {},
)
| 155 | * ``` |
| 156 | */ |
| 157 | export function encodeIntoBase32( |
| 158 | input: string | Uint8Array_ | ArrayBuffer, |
| 159 | output: Uint8Array_, |
| 160 | options: Base32Options = {}, |
| 161 | ): number { |
| 162 | options.alphabet ??= "base32"; |
| 163 | if (typeof input === "string") { |
| 164 | input = new TextEncoder().encode(input) as Uint8Array_; |
| 165 | } else if (input instanceof ArrayBuffer) { |
| 166 | input = new Uint8Array(input); |
| 167 | } |
| 168 | const min = calcSizeBase32((input as Uint8Array_).length); |
| 169 | if (output.length < min) { |
| 170 | throw new RangeError("Cannot encode input as base32: Output too small"); |
| 171 | } |
| 172 | output = output.subarray(0, min); |
| 173 | const i = min - (input as Uint8Array_).length; |
| 174 | output.set(input as Uint8Array_, i); |
| 175 | return encode(output, i, 0, alphabet[options.alphabet], padding); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * `decodeBase32` takes an input source and decodes it into a |
no test coverage detected