function _arrayBufferToBase64( buffer ) {
    var binary = '';
    var bytes = new Uint8Array( buffer );
    var len = bytes.byteLength;
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode( bytes[ i ] );
    }
    return window.btoa( binary );
}

but, non-native implementations are faster e.g. https://gist.github.com/958841 see http://jsperf.com/encoding-xhr-image-data/6

jsPerf.com is jsPerf.app now: https://jsperf.app/encoding-xhr-image-data/51

Updated benchmarks: https://jsben.ch/wnaZC

Answer from mobz on Stack Overflow
🌐
GitHub
gist.github.com › jonleighton › 958841
Encode an ArrayBuffer as a base64 string · GitHub
@Teamop this way wont work for ArrayBuffer larger than 30k bytes. While this thread was about "Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then use window.btoa' step" so I'm going a bit off topic, but there is a way to avoid the "larger than 30k bytes" issues using reduce.
🌐
npm
npmjs.com › package › byte-base64
byte-base64 - npm
August 18, 2020 - In particular, atob and btoa only support ASCII strings. ... bytesToBase64(bytes: number[] | Uint8Array): string - Encodes a Uint8Array or JS array of bytes to a base64-encoded string.
      » npm install byte-base64
    
Published: Aug 18, 2020
Version: 1.1.0
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › fromBase64
Uint8Array.fromBase64() - JavaScript - MDN Web Docs
If you already have an array buffer allocated and you want to populate it, use the instance method Uint8Array.prototype.setFromBase64() instead. ... A base64 string encoding bytes to convert to a Uint8Array.
🌐
EyeHunts
tutorial.eyehunts.com › home › byte array to base64 javascript | examples code
Byte Array to Base64 JavaScript | Simple Examples code
December 9, 2021 - Convert received arrayBuffer value into Base64 encoded string and then we write a file using toBinary() function of CFML bypassing Base64 encoded string in it. Below is custom JavaScript function arrayBufferToBase64() to accomplish the requirement.
🌐
GitHub
gist.github.com › llzes › 24fe0a9b3d786d48f2b3932a633d5b2b
Byte to Base64 implementation in JavaScript · GitHub
Byte to Base64 implementation in JavaScript · Raw · base64ToByte.js · This file contains hidden or 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.
🌐
IQCode
iqcode.com › code › javascript › convert-base64-string-to-byte-array-javascript
convert base64 string to byte array javascript Code Example
November 4, 2021 - javascript base64 encode byte array bytearray to base64 js byte array to base64 in javascript byte to base64 javascript javascript bytes to base64 nodejs base64 to byte array base64 to byte array js js string to byte array and base64 encode convert byte to base64 string javascript js base64 encode byte array convert byte array to base64 string js from byte base64 to base64 javascript array byte to base64 js javascript array of bytes to base64 node js base64 to byte array javascript byte array to base64 convert 2048 to byte array using base64 decoder javascript convert string to byte array usin
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 60730932 › how-to-convert-byte-array-to-base64
javascript - How to convert byte array to base64 - Stack Overflow
In this post (Creating a Blob from a base64 string in JavaScript) they take base64 and convert to a byte array. I haven't been able to figure out how to convert byte array back in to base64 code. I
🌐
Grafana
community.grafana.com › grafana k6 › oss support
Base64 encode ArrayBuffer - OSS Support - Grafana Labs Community Forums
December 7, 2020 - I have a set of bytes in an ArrayBuffer. I need to base64 encode this in k6. How do I accomplish this? In node.js it is data.toString(‘base64’) in browsers the btoa() function seems to be the way to go. Neither of the…
🌐
Stack Overflow
stackoverflow.com › questions › 24761778 › javascript-encode-byte-array-to-base64
encoding - Javascript : Encode byte [ ] array to base64 - Stack Overflow
Now I would like to encode bytes[ ] to base64 format. Is there a library to do that? I will appreciate your help! ... Thanks, but they don't seem to work with byte[ ] . ... Save this answer. ... Show activity on this post. btoa and atob work with strings, which they treat as arrays of bytes, so to use these two functions, you should first convert your array of integers (provided they fall in the range 0-255) into a string.
🌐
GitHub
github.com › enepomnyaschih › byte-base64
GitHub - enepomnyaschih/byte-base64: base64 utilities for TypeScript and JavaScript. · GitHub
May 15, 2021 - This library allows you to encode all the following data structures to a base64-encoded string and back: ... As opposed to this implementation, atob and btoa only support ASCII strings. ... bytesToBase64(bytes: number[] | Uint8Array): string - ...
Author: enepomnyaschih
🌐
Linode
linode.com › docs › guides › javascript-base-64-decode
How to Use JavaScript Base 64 to Decode and Encode | Linode Docs
March 29, 2023 - It then translates these values into the Base64 set of printable characters. Developers can encode strings into Base64 in JavaScript using the btoa function. The atob function can decode the Base64 string back to its original format.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-byte-array-to-string-in-javascript
JavaScript – Convert Byte Array to String | GeeksforGeeks
November 26, 2024 - This is because characters ... NPM(Node Package Manager) is a package manager of Node.js packages. There is an NPM package called arraybuffer-to-string used to decode array buffers in actual strings.
🌐
npm
npmjs.com › package › base64-js
base64-js - npm
November 11, 2020 - Base64 encoding/decoding in pure JS. Latest version: 1.5.1, last published: 6 years ago. Start using base64-js in your project by running `npm i base64-js`. There are 3297 other projects in the npm registry using base64-js.
      » npm install base64-js
    
Published: Nov 11, 2020
Version: 1.5.1
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › setFromBase64
Uint8Array.prototype.setFromBase64() - JavaScript | MDN
Chunks will never be split (because the remaining bits cannot be partially "put back" into the base64 without completely re-encoding it); if the next chunk cannot fit into the remainder of the array, it will be entirely unread, resulting in the last one or two bytes of the array not being written.