MCPcopy Create free account
hub / github.com/denoland/std / encodeIntoBase32

Function encodeIntoBase32

encoding/unstable_base32.ts:157–176  ·  view source on GitHub ↗
(
  input: string | Uint8Array_ | ArrayBuffer,
  output: Uint8Array_,
  options: Base32Options = {},
)

Source from the content-addressed store, hash-verified

155 * ```
156 */
157export 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

Callers 1

Calls 3

calcSizeBase32Function · 0.90
encodeFunction · 0.90
setMethod · 0.65

Tested by

no test coverage detected