(
input: string | Uint8Array_ | ArrayBuffer,
output: Uint8Array_,
options: Base64Options = {},
)
| 138 | * ``` |
| 139 | */ |
| 140 | export function encodeIntoBase64( |
| 141 | input: string | Uint8Array_ | ArrayBuffer, |
| 142 | output: Uint8Array_, |
| 143 | options: Base64Options = {}, |
| 144 | ): number { |
| 145 | options.alphabet ??= "base64"; |
| 146 | if (typeof input === "string") { |
| 147 | input = new TextEncoder().encode(input) as Uint8Array_; |
| 148 | } else if (input instanceof ArrayBuffer) { |
| 149 | input = new Uint8Array(input); |
| 150 | } |
| 151 | const min = calcSizeBase64((input as Uint8Array_).length); |
| 152 | if (output.length < min) { |
| 153 | throw new RangeError("Cannot encode input as base64: Output too small"); |
| 154 | } |
| 155 | output = output.subarray(0, min); |
| 156 | const i = min - (input as Uint8Array_).length; |
| 157 | output.set(input as Uint8Array_, i); |
| 158 | const o = encode(output, i, 0, alphabet[options.alphabet], padding); |
| 159 | if (options.alphabet === "base64url") { |
| 160 | const i = output.indexOf(padding, o - 2); |
| 161 | if (i > 0) return i; |
| 162 | } |
| 163 | return o; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * `decodeBase64` takes an input source and decodes it into a |
no test coverage detected