MCPcopy Create free account
hub / github.com/denoland/std / encodeBase64

Function encodeBase64

encoding/base64.ts:52–63  ·  view source on GitHub ↗
(data: ArrayBuffer | Uint8Array | string)

Source from the content-addressed store, hash-verified

50 * ```
51 */
52export function encodeBase64(data: ArrayBuffer | Uint8Array | string): string {
53 if (typeof data === "string") {
54 data = new TextEncoder().encode(data) as Uint8Array_;
55 } else if (data instanceof ArrayBuffer) data = new Uint8Array(data).slice();
56 else data = data.slice();
57 const [output, i] = detach(
58 data as Uint8Array_,
59 calcSizeBase64((data as Uint8Array_).length),
60 );
61 encode(output, i, 0, alphabet, padding);
62 return new TextDecoder().decode(output);
63}
64
65/**
66 * Decodes a base64-encoded string.

Callers 5

base64_test.tsFile · 0.90
serializeBinaryFunction · 0.90
constructorMethod · 0.50

Calls 4

detachFunction · 0.90
calcSizeBase64Function · 0.90
encodeFunction · 0.90
sliceMethod · 0.45

Tested by

no test coverage detected