Kit
Functions

getBase64Codec

getBase64Codec(): VariableSizeCodec<string>

Returns a codec for encoding and decoding base-64 strings.

This codec serializes strings using a base-64 encoding scheme, commonly used for data encoding in URLs, cryptographic keys, and binary-to-text encoding.

Returns

VariableSizeCodec<string>

A VariableSizeCodec<string> for encoding and decoding base-64 strings.

Example

Encoding and decoding a base-64 string.

const codec = getBase64Codec();
const bytes = codec.encode('hello+world'); // 0x85e965a3ec28ae57
const value = codec.decode(bytes);         // "hello+world"

Remarks

This codec does not enforce a size boundary. It will encode and decode all bytes necessary to represent the string.

If you need a fixed-size base-64 codec, consider using fixCodecSize.

const codec = fixCodecSize(getBase64Codec(), 8);

If you need a size-prefixed base-64 codec, consider using addCodecSizePrefix.

const codec = addCodecSizePrefix(getBase64Codec(), getU32Codec());

Separate getBase64Encoder and getBase64Decoder functions are available.

const bytes = getBase64Encoder().encode('hello+world');
const value = getBase64Decoder().decode(bytes);

See

On this page