-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathworker.js
More file actions
36 lines (31 loc) · 727 Bytes
/
worker.js
File metadata and controls
36 lines (31 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import LibRawModule from './libraw.js';
let ready;
let LibRawClass;
let raw;
async function initLibRaw() {
ready = (async () => {
const module = await LibRawModule();
LibRawClass = module.LibRaw;
raw = new LibRawClass();
})();
}
initLibRaw();
function isTypedArray(obj) {
return ArrayBuffer.isView(obj) && !(obj instanceof DataView);
}
self.onmessage = async (event) => {
const {fn, args} = event.data;
try {
await ready;
const out = raw[fn](...args);
const transferList = [];
for (const key in out) {
const value = out[key];
if (isTypedArray(value))
transferList.push(value.buffer);
}
self.postMessage({out}, transferList);
} catch (err) {
self.postMessage({error: err.message});
}
};