mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Integrate WASI module with Squoosh UI
This commit is contained in:
@@ -29,3 +29,16 @@ export function initEmscriptenModule<T extends EmscriptenWasm.Module>(
|
||||
export function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer> {
|
||||
return new Response(blob).arrayBuffer();
|
||||
}
|
||||
|
||||
export async function instantiateStreaming(
|
||||
resp: Response | PromiseLike<Response>,
|
||||
importObj?: WebAssembly.Imports,
|
||||
): Promise<WebAssembly.WebAssemblyInstantiatedSource> {
|
||||
if (WebAssembly.instantiateStreaming) {
|
||||
return WebAssembly.instantiateStreaming(resp, importObj);
|
||||
}
|
||||
return WebAssembly.instantiate(
|
||||
await Promise.resolve(resp).then((r) => r.arrayBuffer()),
|
||||
importObj,
|
||||
);
|
||||
}
|
||||
|
||||
32
src/features/worker-utils/wasi-utils.ts
Normal file
32
src/features/worker-utils/wasi-utils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2021 Google Inc. All Rights Reserved.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function makeEverythingElseThrow(obj: { [x: string]: {} }): {} {
|
||||
return new Proxy(obj, {
|
||||
get(target, prop: string) {
|
||||
if (prop in target) {
|
||||
return target[prop];
|
||||
}
|
||||
return () => {
|
||||
throw Error(`${prop} not implemented`);
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function makeWasiEnv() {
|
||||
return {
|
||||
environ_sizes_get: () => 0,
|
||||
environ_get: () => 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user