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;
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



- 最新
- 最热
只看作者