Skip to content
Snippets Groups Projects
Verified Commit a54cb406 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

refactor: better base64 utils

more docs
parent 3a906c6e
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ A Game Boy emulator that is written in Rust 🦀.
* Web and SDL front-ends
* Fullscreen mode
* Support for multiple MBCs: MBC1, MBC2, MBC3, and MBC5
* Transparent RAM saving using [Web Storage API](https://developer.mozilla.org/docs/Web/API/Window/localStorage)
* Variable CPU clock speed
* Debug mode: VRAM and registers
......
export const bufferToBase64 = (buffer: Uint8Array) => {
const array = Array(buffer.length)
.fill("")
const data = Array(buffer.length)
.fill(null)
.map((_, i) => String.fromCharCode(buffer[i]))
.join("");
const base64 = btoa(array);
const base64 = btoa(data);
return base64;
};
export const base64ToBuffer = (base64: string) => {
const data = window.atob(base64);
const length = data.length;
const buffer = new Uint8Array(length);
for (let i = 0; i < length; i++) {
buffer[i] = data.charCodeAt(i);
}
const data = atob(base64);
const array = Array(data.length)
.fill(null)
.map((_, i) => data.charCodeAt(i));
const buffer = new Uint8Array(array);
return buffer;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment