File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 11import * as typ from "typed-cstruct" ;
22
33import {
4- libraw_data_t ,
54 libraw_imgother_t ,
65 libraw_iparams_t ,
76 libraw_lensinfo_t ,
@@ -34,14 +33,28 @@ export class LibRaw implements Disposable {
3433 constructor ( ) {
3534 this . setup ( ) ;
3635 }
37- static async initialize ( ) {
36+ static async initialize ( wasm ?: Response | ArrayBuffer ) {
3837 if ( LibRaw . modulePromise === undefined ) {
39- const mod : Promise < LibRawWasmModule > = initializeLibRawWasm ( ) ;
38+ const mod : Promise < LibRawWasmModule > = initializeLibRawWasm ( {
39+ instantiateWasm : LibRaw . createInstantiateWasm ( wasm ) ,
40+ } ) ;
4041 LibRaw . modulePromise = mod ;
4142 LibRaw . module = await mod ;
4243 }
4344 return await LibRaw . modulePromise ;
4445 }
46+ private static createInstantiateWasm ( wasm ?: Response | ArrayBuffer ) {
47+ if ( wasm === undefined ) return undefined ;
48+ return async (
49+ importObject : WebAssembly . Imports ,
50+ cb : ( instance : WebAssembly . Instance , module : WebAssembly . Module ) => void ,
51+ ) => {
52+ const instantiated = await ( wasm instanceof Response
53+ ? WebAssembly . instantiateStreaming ( wasm , importObject )
54+ : WebAssembly . instantiate ( wasm , importObject ) ) ;
55+ cb ( instantiated . instance , instantiated . module ) ;
56+ } ;
57+ }
4558 async waitUntilReady ( ) {
4659 await LibRaw . modulePromise ;
4760 }
You can’t perform that action at this time.
0 commit comments