From 88cdf858a61fa6b585c6dcbf96f86d716cb43696 Mon Sep 17 00:00:00 2001
From: eric2788 <tsukiko852@gmail.com>
Date: Mon, 8 Jan 2024 14:15:44 +0800
Subject: [PATCH] tried to keep wasm but using base64

---
 src/adapters/websocket-hook.js | 5 +++--
 src/utils/misc.ts              | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/adapters/websocket-hook.js b/src/adapters/websocket-hook.js
index 80aa5bac..1ecd0749 100644
--- a/src/adapters/websocket-hook.js
+++ b/src/adapters/websocket-hook.js
@@ -1,11 +1,12 @@
 import { injectFuncAsListener } from "~utils/event"
 import { sendBLiveMessage } from "~utils/messaging"
-import wasmUrl from "raw:~assets/brotli-dec.wasm"
+import wasmBase64 from "data-base64:~assets/brotli-dec.wasm"
 import init from 'brotli-dec-wasm/pkg/index'
+import { base64ToArrayBuffer } from "~utils/misc"
 
 var decompress = null
 
-const loadWasm = init(wasmUrl).then(output => {
+const loadWasm = init(base64ToArrayBuffer(wasmBase64.split('data:application/wasm;base64,')[1])).then(output => {
   decompress = output.decompress
   console.info('wasm loaded.')
 })
diff --git a/src/utils/misc.ts b/src/utils/misc.ts
index 58470a58..7646c23d 100644
--- a/src/utils/misc.ts
+++ b/src/utils/misc.ts
@@ -86,4 +86,13 @@ export function randomRange(min: number, max: number): number {
 
 export function randomNumber(length: number = 20): number {
     return Math.round(Math.random() * (10 ** length))
+}
+
+export function base64ToArrayBuffer(base64: string): ArrayBuffer {
+    const binaryString = atob(base64)
+    const bytes = new Uint8Array(binaryString.length)
+    for (var i = 0; i < binaryString.length; i++) {
+        bytes[i] = binaryString.charCodeAt(i)
+    }
+    return bytes.buffer
 }
\ No newline at end of file