Closed swissspidy closed 10 months ago
Great suggestion, I think this has been brought up a few times in some other issues.
I can't put any guarantees on when I might be able to work on this. If you or someone else would like to scaffold a Pull Request with the changes it would be a great help š
I would eventually like to refactor the whole init
method syntax, but to keep the scope focused for the initial change I think the API should look like:
type InitOptions = EmscriptenWasm.ModuleOpts;
export async function init(module?: WebAssembly.Module, options?: InitOptions): Promise<void> {
// ....
}
This would also allow others to modify other relevant emscripten module options that might suit their use case.
Thanks @swissspidy I actually had some spare time to implement this. I went with the simplest approach to avoid a breaking change.
import { default as encodeJpeg, init as initJpeg } from '@jsquash/jpeg/encode';
await initJpeg( undefined, {
locateFile: () =>
'https://cdn.jsdelivr.net/npm/@jsquash/jpeg@1.4.0/codec/enc/mozjpeg_enc.wasm',
} );
const buffer = await encodeJpeg( imageData );
Your use case should hopefully work now with @jsquash/jpeg@1.4.0+
š¤ ā keep me posted if it doesn't
Is your feature request related to a problem? Please describe.
Due to server restrictions in my project, it's not possible to load the WASM file from the same location as the JS is loaded.
Describe the solution you'd like
Providing a way to override the WASM file location by specifying a custom
locateFile
would help resolve my use case.Describe alternatives you've considered
Right now I'm simply patching this package
This way I can do:
Hacky, but works
Additional context
Allowing to override
locateFile
is common in similar projects such as mediainfo.js or ffmpeg.wasm.