ArrayBuffer.js 409 Bytes
Newer Older
1 2 3 4
// shameless copy from
// https://stackoverflow.com/a/9458996
// This is because base64-codec/Data.Base64.encodeBase64 was too slow

5
export function arrayBufferToBase64Impl(buffer) {
6 7 8 9 10 11 12 13
    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 );
}