Kagami / vmsg

:musical_note: Library for creating voice messages
https://kagami.github.io/vmsg/
Creative Commons Zero v1.0 Universal
348 stars 58 forks source link

embed vmsg.wasm directly #8

Closed transitive-bullshit closed 6 years ago

transitive-bullshit commented 6 years ago

It'd be great if vmsg.wasm was embedded directly via an ArrayBuffer or as a compile-time step.

Having the end user reference the URL of vmsg.wasm is pretty clunky, though I understand why it's setup that way at the moment.

Kagami commented 6 years ago

Unfortunately it won't be effecient. The whole point of WebAssembly is that it can be parsed fast. If you put it back into JavaScript file, you lose main benefits - compactness and small parsing time.

If you wish you can include vmsg.wasm with e.g. arraybuffer-loader:

const buffer = require("arraybuffer!./vmsg.wasm");
const blob = new Blob([buffer], {type: "application/wasm"});
const wasmURL = URL.createObjectURL(blob);

that will work.

transitive-bullshit commented 6 years ago

I ended up doing something similar for react-mp3-recorder. This doesn't seem particularly efficient, however.

Kagami commented 6 years ago

I've just tried, seems like you can just pass data URI to fetch directly:

> url = 'data:application/wasm;base64,' + btoa("123")
"data:application/wasm;base64,MTIz"
> fetch(url).then(res => res.arrayBuffer()).then(b => console.log(new Uint8Array(b)))
Uint8Array(3) [49, 50, 51]
transitive-bullshit commented 6 years ago

Good call -- just updated my impl.

Kagami commented 6 years ago

Can we close this now?