//arraybuffer生成base64的图片
```
arrayBufferToBase64(buffer) {
return (
"data:image/jpeg;base64," +
window.btoa(String.fromCharCode(...new Uint8Array(buffer)))
);
},
```
//arraybuffer转blob
```
arrayBufferToBlob(arrayBuffer, filename) {
return new Blob([arrayBuffer], { type: filename });
}
```
//blob转arraybuffer
```
blobToArrayBuffer(blob, callback) {
let reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = function () {
return callback(this.result);
}
```
//blob转化成file
```
blobToFile(blob, filename){
returnnewFile([blob], filename, {type: blob.type })
```
//base64转化成file
```
dataURLtoFile(dataurl, filename){
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
}
```
//blob转化成base64
```
blobToDataURI(blob, callback){
varreader =newFileReader();
reader.readAsDataURL(blob);
reader.onload =function(e){ callback(e.target.result); }
}
```