Async buffer->BASE64 conversion (#1481)

* Async buffer->BASE64 conversion

* ESLint fixes
This commit is contained in:
jurajmatus
2022-08-10 18:31:04 +02:00
committed by GitHub
parent 76f7a6e279
commit 537e843a49
2 changed files with 15 additions and 1 deletions

View File

@@ -480,6 +480,20 @@ exports.LoadUtils = () => {
return window.btoa(binary);
};
window.WWebJS.arrayBufferToBase64Async = (arrayBuffer) =>
new Promise((resolve, reject) => {
const blob = new Blob([arrayBuffer], {
type: 'application/octet-stream',
});
const fileReader = new FileReader();
fileReader.onload = () => {
const [, data] = fileReader.result.split(',');
resolve(data);
};
fileReader.onerror = (e) => reject(e);
fileReader.readAsDataURL(blob);
});
window.WWebJS.getFileHash = async (data) => {
let buffer = await data.arrayBuffer();
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);