Created
October 2, 2020 07:23
-
-
Save shagamemnon/3ad07f1b2edbbd2f690bf96e87b44786 to your computer and use it in GitHub Desktop.
Decode Base64 encoded text in Cloudflare Workers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Demo: https://cloudflareworkers.com/#6168c0dbeb076f1e3ac7eb102082361f:https://www.google.com/ */ | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
function fromBinary(msg) { | |
const ui = new Uint8Array(msg.length) | |
for (let i = 0; i < msg.length; ++i) { | |
ui[i] = msg.charCodeAt(i) | |
} | |
return ui | |
} | |
async function handleRequest(request) { | |
const encodedData = fromBinary(atob(`zG7JdnPN2ahJesk2m14XYQ==`)) | |
console.log(encodedData) | |
return new Response(encodedData, { | |
headers: { | |
'content-type': 'application/octet-stream' | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment