1. ArrayBuffer转base64
function translateArrayBufferToBase64(buffer){
const bytes = new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), '')
return window.btoa(bytes);
}
2. base64转ArrayBuffer
function translateBase64ToArrayBuffer(base64){
const binaryStr = window.atob(base64);
const byteLength = binaryStr.length;
const bytes = new Uint8Array(byteLength);
for(let i=0;i<byteLength;i++){
bytes[i] = binaryStr.charCodeAt(i);
}
return bytes.buffer;
}
asdasd