encodeIntoBase32

import { encodeIntoBase32 } from "jsr:@ende/encoding/unstable-base32";

function ยท experimental

function encodeIntoBase32(input: string | Uint8Array_ | ArrayBuffer, output: Uint8Array_, options: Base32Options = [UNSUPPORTED]): number

encodeIntoBase32 takes an input source and encodes it as base32 into the output buffer.

input: string | Uint8Array_ | ArrayBuffer

the source to encode.

output: Uint8Array_

the buffer to write the encoded source to.

options: Base32Options = [UNSUPPORTED]

the options to use for encoding.

Returns

the number of bytes written to the buffer.

Example: Basic Usage

import { assertEquals } from "@ende/assert";
import {
  calcSizeBase32,
  encodeBase32,
  encodeIntoBase32,
} from "@ende/encoding/unstable-base32";

const prefix = "data:url/fake,";
const input = await Ende.readFile("./ende.lock");
const output = new Uint8Array(prefix.length + calcSizeBase32(input.length));

const o = new TextEncoder().encodeInto(prefix, output).written;
encodeIntoBase32(input, output.subarray(o), { alphabet: "base32" });
assertEquals(
  new TextDecoder().decode(output),
  "data:url/fake," +
    encodeBase32(await Ende.readFile("./ende.lock"), { alphabet: "base32" }),
);

Source