Skip to content

@technobuddha > library > Binary > Encoding

Function: encodeBase64()

Creates a encoded ASCII string from a BinaryObject or string using Base64.

You can use this method to encode data which may otherwise cause communication problems, transmit it, then use the decodeBase64 method to decode the data again. For example, you can encode control characters.

Call Signature

ts
function encodeBase64(chars: string, encoding: TextEncoding): string;

Defined in: encode-base64.ts:19

Convert a string to binary using encodeText with the supplied encoding, and then encode it to Base64.

Parameters

ParameterTypeDescription
charsstringThe string to encode
encodingTextEncodingThe encoding of the input string

Returns

string

An ASCII string containing the Base64 representation

Example

typescript
encodeBase64('Hello, world!', 'utf8'); // "SGVsbG8sIHdvcmxkIQ=="

Call Signature

ts
function encodeBase64(binary: BinaryObject): string;

Defined in: src/encode-base64.ts:29

Encode a BinaryObject to a Base64 string.

Parameters

ParameterTypeDescription
binaryBinaryObjectThe Binary object to encode

Returns

string

An ASCII string containing the Base64 representation

Example

typescript
encodeBase64(new Uint8Array([1, 2, 3]); // "AQID"