Skip to content

Instantly share code, notes, and snippets.

@shagamemnon
Created October 2, 2020 07:23
Show Gist options
  • Save shagamemnon/3ad07f1b2edbbd2f690bf96e87b44786 to your computer and use it in GitHub Desktop.
Save shagamemnon/3ad07f1b2edbbd2f690bf96e87b44786 to your computer and use it in GitHub Desktop.
Decode Base64 encoded text in Cloudflare Workers
/* 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