import * as Result from "../Result.ts"; import { EncodingError } from "./EncodingError.ts"; /** * Encodes the given value into a Base64 (RFC 4648) string. * * **When to use** * * Use to encode text or bytes as a standard padded Base64 string for storage or * transport. * * **Details** * * String inputs are encoded as UTF-8 bytes before Base64 encoding. * Each unpaired UTF-16 surrogate is replaced with U+FFFD (�). * `Uint8Array` inputs are encoded directly. The output uses the standard * RFC 4648 alphabet with `=` padding. * * **Example** (Encoding Base64 strings and bytes) * * ```ts import.meta.vitest * import { Base64 } from "effect/encoding" * * Base64.encode("hello") // => "aGVsbG8=" * * const bytes = new Uint8Array([72, 101, 108, 108, 111]) * Base64.encode(bytes) // => "SGVsbG8=" * ``` * * @see {@link decode} for decoding standard Base64 to bytes * @see {@link decodeString} for decoding standard Base64 to UTF-8 text * * @stability stable * @category encoding * @since 4.0.0 */ export declare const encode: (input: Uint8Array | string) => string; /** * Decodes a Base64 (RFC 4648) string into bytes safely. * * **When to use** * * Use to decode a standard padded Base64 string into bytes without throwing on * invalid input. * * **Details** * * Returns `Result.succeed` with a `Uint8Array` when decoding succeeds, or * `Result.fail` with an `EncodingError` when the input is not valid Base64. * * **Example** (Decoding Base64 bytes) * * ```ts import.meta.vitest * import { Result } from "effect" * import { Base64 } from "effect/encoding" * * Base64.decode("SGVsbG8=") // => Result.succeed(new Uint8Array([72, 101, 108, 108, 111])) * ``` * * @stability stable * @category decoding * @since 4.0.0 */ export declare const decode: (str: string) => Result.Result; /** * Decodes a Base64 (RFC 4648) string into UTF-8 text safely. * * **When to use** * * Use to decode a standard padded Base64 string into UTF-8 text without * throwing on invalid input. * * **Details** * * Returns `Result.succeed` with the decoded text when decoding succeeds, or * `Result.fail` with an `EncodingError` when the input is not valid Base64. * * **Example** (Decoding Base64 strings) * * ```ts import.meta.vitest * import { Result } from "effect" * import { Base64 } from "effect/encoding" * * Base64.decodeString("aGVsbG8=") // => Result.succeed("hello") * ``` * * @stability stable * @category decoding * @since 4.0.0 */ export declare const decodeString: (str: string) => Result.Result; /** * Encodes the given value into a Base64 (RFC 4648) string without `=` * padding. * * **When to use** * * Use when a format requires standard Base64 without padding, such as the * `grpc-status-details-bin` value in the Connect protocol. * * **Details** * * Same as {@link encode}, but drops the trailing `=` padding. * * **Example** (Encoding unpadded Base64) * * ```ts import.meta.vitest * import { Base64 } from "effect/encoding" * * Base64.encodeUnpadded("hello") // => "aGVsbG8" * ``` * * @see {@link encode} for padded output * @see {@link decodeLenient} for decoding unpadded Base64 * * @stability stable * @category encoding * @since 4.1.5 */ export declare const encodeUnpadded: (input: Uint8Array | string) => string; /** * Decodes Base64 in the standard or the URL-safe alphabet, with or without * padding, into bytes safely. * * **When to use** * * Use when a format accepts either Base64 alphabet, such as the protobuf JSON * mapping for `bytes` fields or the Connect protocol. * * **Details** * * Returns `Result.succeed` with a `Uint8Array` when decoding succeeds, or * `Result.fail` with an `EncodingError` holding the original input when the * input is not valid. Each input must use a single alphabet. CR/LF are * ignored, and other whitespace is rejected. * * **Example** (Decoding either Base64 alphabet) * * ```ts import.meta.vitest * import { Result } from "effect" * import { Base64 } from "effect/encoding" * * Base64.decodeLenient("+/8=") // => Result.succeed(new Uint8Array([251, 255])) * Base64.decodeLenient("-_8") // => Result.succeed(new Uint8Array([251, 255])) * ``` * * @see {@link decode} for strict standard Base64 * * @stability stable * @category decoding * @since 4.1.5 */ export declare const decodeLenient: (str: string) => Result.Result; //# sourceMappingURL=Base64.d.ts.map