2020-08-20 02:10:42 +02:00
|
|
|
import { env } from '../env';
|
|
|
|
export function bufferToImage(buf) {
|
2020-08-18 14:04:33 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (!(buf instanceof Blob)) {
|
|
|
|
return reject('bufferToImage - expected buf to be of type: Blob');
|
|
|
|
}
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = () => {
|
|
|
|
if (typeof reader.result !== 'string') {
|
|
|
|
return reject('bufferToImage - expected reader.result to be a string, in onload');
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
const img = env.getEnv().createImageElement();
|
2020-08-18 14:04:33 +02:00
|
|
|
img.onload = () => resolve(img);
|
|
|
|
img.onerror = reject;
|
|
|
|
img.src = reader.result;
|
|
|
|
};
|
|
|
|
reader.onerror = reject;
|
|
|
|
reader.readAsDataURL(buf);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=bufferToImage.js.map
|