15 self.onmessage = async function (event) {
16 const { b64Source } = event.data;
18 const decodeBase64 = (base64: string) => {
22 const decodeWasmBinary = (base64: string) => {
23 const text = decodeBase64(base64);
24 const binary = new Uint8Array(new ArrayBuffer(text.length));
25 for (let i = 0; i < text.length; i++) {
26 binary[i] = text.charCodeAt(i);
31 const loadWasmModule = async (source: string) => {
32 const wasmBinary = decodeWasmBinary(source);
33 const result = await WebAssembly.instantiate(wasmBinary);
34 return result as typeof result & WasmApi;
37 const result = await loadWasmModule(b64Source);
38 const b64OutputPtr = result.instance.exports.b64_output.value;
39 const startTime = Date.now();
40 const b64OutputLen = result.instance.exports.solve();
41 const endTime = Date.now();
42 const duration = endTime - startTime;
43 const b64Output = new Uint8Array(result.instance.exports.memory.buffer, b64OutputPtr, b64OutputLen);
44 const b64 = new TextDecoder().decode(b64Output);
45 self.postMessage(b64 + `, ${duration}`);