(input: Uint8Array | string): stringEncodes the given value into a base64 (RFC4648) 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.
Uint8Array inputs are encoded directly. The output uses the standard
RFC4648 alphabet with = padding.
Example (Encoding Base64 strings and bytes)
import { Encoding } from "effect"
// Encode a string
console.log(Encoding.encodeBase64("hello")) // "aGVsbG8="
// Encode binary data
const bytes = new Uint8Array([72, 101, 108, 108, 111])
console.log(Encoding.encodeBase64(bytes)) // "SGVsbG8="export const const encodeBase64: (
input: Uint8Array | string
) => string
Encodes the given value into a base64 (RFC4648) 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.
Uint8Array inputs are encoded directly. The output uses the standard
RFC4648 alphabet with = padding.
Example (Encoding Base64 strings and bytes)
import { Encoding } from "effect"
// Encode a string
console.log(Encoding.encodeBase64("hello")) // "aGVsbG8="
// Encode binary data
const bytes = new Uint8Array([72, 101, 108, 108, 111])
console.log(Encoding.encodeBase64(bytes)) // "SGVsbG8="
encodeBase64: (input: string | Uint8Array<ArrayBufferLike>input: interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array | string) => string = (input: string | Uint8Array<ArrayBufferLike>input) =>
typeof input: string | Uint8Array<ArrayBufferLike>input === "string" ? const base64EncodeUint8Array: (
bytes: Uint8Array
) => string
base64EncodeUint8Array(const encoder: TextEncoderencoder.TextEncoder.encode(input?: string): Uint8Array<ArrayBuffer>The TextEncoder.encode() method takes a string as input, and returns a Global_Objects/Uint8Array containing the text given in parameters encoded with the specific method for that TextEncoder object.
encode(input: stringinput)) : const base64EncodeUint8Array: (
bytes: Uint8Array
) => string
base64EncodeUint8Array(input: Uint8Array<ArrayBufferLike>input)