Skip to content

Commit

Permalink
tried to keep wasm but using base64
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Jan 8, 2024
1 parent 052ee5e commit 88cdf85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/adapters/websocket-hook.js
Original file line number Diff line number Diff line change
@@ -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.')
})
Expand Down
9 changes: 9 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 88cdf85

Please sign in to comment.