2022-11-28 05:50:34 +03:00
|
|
|
/**
|
2022-12-30 19:28:26 +03:00
|
|
|
* [Base64 encoding](link-wiki-base64) using 6-bit words to encode
|
2022-11-28 05:50:34 +03:00
|
|
|
* arbitrary bytes into a string using 65 printable symbols, the
|
|
|
|
* upper-case and lower-case alphabet, the digits ``0`` through ``9``,
|
|
|
|
* ``"+"`` and ``"/"`` with the ``"="`` used for padding.
|
|
|
|
*
|
2022-12-03 05:23:13 +03:00
|
|
|
* @_subsection: api/utils:Base64 Encoding [about-base64]
|
2022-11-28 05:50:34 +03:00
|
|
|
*/
|
2022-09-09 06:21:08 +03:00
|
|
|
import { getBytes, getBytesCopy } from "./data.js";
|
2022-09-05 23:14:43 +03:00
|
|
|
|
|
|
|
import type { BytesLike } from "./data.js";
|
|
|
|
|
|
|
|
|
2022-09-09 10:37:38 +03:00
|
|
|
/**
|
2022-11-28 05:50:34 +03:00
|
|
|
* Decodes the base-64 encoded %%value%%.
|
2022-09-09 10:37:38 +03:00
|
|
|
*/
|
2022-11-28 05:50:34 +03:00
|
|
|
export function decodeBase64(value: string): Uint8Array {
|
|
|
|
return getBytesCopy(Buffer.from(value, "base64"));
|
2022-09-05 23:14:43 +03:00
|
|
|
};
|
|
|
|
|
2022-09-09 10:37:38 +03:00
|
|
|
/**
|
2022-11-28 05:50:34 +03:00
|
|
|
* Encodes %%data%% as a base-64 encoded string.
|
2022-09-09 10:37:38 +03:00
|
|
|
*/
|
2022-09-05 23:14:43 +03:00
|
|
|
export function encodeBase64(data: BytesLike): string {
|
2022-09-09 06:21:08 +03:00
|
|
|
return Buffer.from(getBytes(data)).toString("base64");
|
2022-09-05 23:14:43 +03:00
|
|
|
}
|