JSFiddle - React, Tailwind, and code Playground

by Alexander Pilafian

JavaScript

function base64ToArrayBuffer(base64) {
    var binaryString = atob(base64);
    var bytes = new Uint8Array(binaryString.length);
    for (var i = 0; i < binaryString.length; i++) {
        bytes[i] = binaryString.charCodeAt(i);
    }
    return bytes;
}

const original = new Uint8Array([2, 4, 8, 16, 32, 64, 128, 255]);
console.log('Original data:', Array.from(original))

const ascii_str = String.fromCharCode.apply(null, original)
const b64 = btoa(ascii_str)

console.log("Base64 encoded:", b64)
const b64_decoded = base64ToArrayBuffer(b64)
console.log("Base64 decoded:", Array.from(b64_decoded))