mirror of
https://github.com/Qortal/Q-Apps-Utils.git
synced 2025-02-11 17:55:55 +00:00
19 lines
455 B
TypeScript
19 lines
455 B
TypeScript
export function uint8ArrayToBase64(byteArray: Uint8Array): string {
|
|
const chars: string[] = Array.from(byteArray).map(byte =>
|
|
String.fromCharCode(byte)
|
|
);
|
|
return btoa(chars.join(""));
|
|
}
|
|
|
|
export function base64ToUint8Array(base64) {
|
|
const binary_string = atob(base64);
|
|
const len = binary_string.length;
|
|
const bytes = new Uint8Array(len);
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
bytes[i] = binary_string.charCodeAt(i);
|
|
}
|
|
|
|
return bytes;
|
|
}
|