Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created November 20, 2019 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/f4862a6d6c80bbf03284aed0f264bef1 to your computer and use it in GitHub Desktop.
Save miguelmota/f4862a6d6c80bbf03284aed0f264bef1 to your computer and use it in GitHub Desktop.
JavasScript ArrayBuffer to base64 and base64 to ArrayBuffer
const arrayBufferToBase64 = (arrayBuffer) => {
return window.btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)))
}
const base64ToArrayBuffer = (str) => {
return Uint8Array.from(window.atob(str), c => c.charCodeAt(0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment