From a3550738ab112d4a66c70b9608a0ad01e69afbbc Mon Sep 17 00:00:00 2001 From: Kwangsoo Yeo Date: Fri, 12 Jul 2024 09:44:09 -0700 Subject: [PATCH] add wasi imports to wasm --- package.json | 2 +- src/utils.ts | 2 +- src/wasm.ts | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c1e2e8f..117a123 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@picovoice/web-utils", - "version": "1.4.1", + "version": "1.4.2", "description": "Picovoice web utility functions", "author": "Picovoice", "license": "Apache-2.0", diff --git a/src/utils.ts b/src/utils.ts index 6f800d7..b15b0c8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,7 +42,7 @@ export function arrayBufferToStringAtIndex( indexEnd++; } const utf8decoder = new TextDecoder('utf-8'); - return utf8decoder.decode(arrayBuffer.subarray(indexStart, indexEnd)); + return utf8decoder.decode(arrayBuffer.slice(indexStart, indexEnd)); } /** diff --git a/src/wasm.ts b/src/wasm.ts index e801ac4..2cb2314 100644 --- a/src/wasm.ts +++ b/src/wasm.ts @@ -37,6 +37,7 @@ export type pv_free_type = (ptr: number) => Promise; * @param wasm The wasm file in base64 string or stream to public path (i.e. fetch("file.wasm")) to initialize. * @param pvError The PvError object to store error details. * @param additionalImports Extra WASM imports. + * @param wasiImports Addition WASI imports. * @returns An object containing the exported functions from WASM. */ export async function buildWasm( @@ -44,6 +45,7 @@ export async function buildWasm( wasm: string | Promise, pvError?: PvError, additionalImports: Record = {}, + wasiImports: Record = {} ): Promise { const setInt = (address: number, value: number) => { const memoryBufferInt32 = new Int32Array(memory.buffer); @@ -404,8 +406,11 @@ export async function buildWasm( pv_file_seek_wasm: pvFileSeekWasm, pv_file_tell_wasm: pvFileTellWasm, pv_file_remove_wasm: pvFileRemoveWasm, - ...additionalImports + ...additionalImports, }, + wasi: { + ...wasiImports, + } }; let instance: WebAssembly.Instance;