Combining OPFS and JSPI #19408
Replies: 1 comment
-
Hi, you can use WasmFS with OPFS by creating and mounting the OPFS backend. We should have better docs on this (as you noticed, the existing WasmFS docs are very out of date), but for now you can see how it's done in our tests, e.g. here. You're right that OPFS has some async operations. There are two ways WasmFS deals with this. First, if you have threads enabled on your application, WasmFS will proxy all the OPFS work to a dedicated worker thread so that your application threads can wait while the worker thread does the asynchronous work. Alternatively, if you build with JSPI enabled, WasmFS will automatically use JSPI to make the async OPFS work look synchronous to your application. Either way, you as the user don't need to do anything special. Unfortunately the WasmFS OPFS backend does not have the ability to use arbitrary |
Beta Was this translation helpful? Give feedback.
-
Hi, i'm relative new to the Wasm/Emscripten world so sry for asking dumb question
i read over at https://emscripten.org/docs/api_reference/Filesystem-API.html#new-file-system-wasmfs
that there wasn't any OPFS backend but there is clearly any activity on the github repo that there now exist a OPFS backend for handling file system
Now i also know that OFPS is not entirely sync and comes with a mix of async and await.
So it would probably also require some asyncify stuff wraps all code to some weird mongo jumbo with lots of complication to change the sync code to start behaving as async (?)
But now i also learned that there is a JSPI that can suspend the code execution more natively without having to wrap code to be asyncified. that is if you use 2
-s ASYNCIFY=2.
but how to i instruct it to also use OPFS?
i don't particularly want emscripten to use the default root map
/
i rather wish to "mount" the a folder of my own choosing by giving it aFileSystemDirectoryHandle
the directory handle could be either a persistent local file folder coming fromFile system access
where i have been granted to read/write to any folder on the clients machine. or it could come from OFPS (navigator.storage.getDirectory
)So please help, give me any advice on how to proceed.
Beta Was this translation helpful? Give feedback.
All reactions