Created
November 20, 2019 02:49
-
-
Save miguelmota/f4862a6d6c80bbf03284aed0f264bef1 to your computer and use it in GitHub Desktop.
JavasScript ArrayBuffer to base64 and base64 to ArrayBuffer
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
const arrayBufferToBase64 = (arrayBuffer) => { | |
return window.btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))) | |
} |
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
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