wasmer-js
wasmer-js copied to clipboard
Saving to IndexedDB instead of memfs
Hello
Is it possible to have a configuration that allows the executing WASI/WASM packages to store to a persistent storage provider such as IndexedDB rather than memfs?
Also my other question is slightly unrelated but can wasm-terminal also run WASM or only WASI packages?
Thanks!
Hi! I have recently implemented some logic in my own code (not part of wasmer) that synchronizes a memdb with an IndexedDB. https://github.com/corwin-of-amber/Web.Author/blob/master/src/net/local.ts
It takes advantage of fs.watch
. Unfortunately, memfs does not implement recursive watch... so I needed to wrap the memfs Volume with my own SubdirectoryVolume:
https://github.com/corwin-of-amber/Web.Author/blob/master/src/infra/volume.ts#L59
Feel free to copy my source 😄
I am afraid the (brilliant) TypeScript implementation of the wasmer runtime has been abandoned for now, so I do not much expect it to progress. But if you happen to add some functionality I am sure they will appreciate PRs.
Thanks will take a look. When writing to memfs does it individually store each file to the db and remove the file from memfs to clear space or does it just place whatever is inside memfs to indexeddb similarly to emscripten idbfs? My only concern would be how this deals with reading large file streams from db without loading anything to memory.
Ah, it's not very smart tbh. It makes a clone of whatever is in the memfs, which it stores in the IndexedDB. Then when you reload the page it reads the entire DB back to memory. Indeed for large files this would be infeasible.
Ah, it's not very smart tbh. It makes a clone of whatever is in the memfs, which it stores in the IndexedDB. Then when you reload the page it reads the entire DB back to memory. Indeed for large files this would be infeasible.
Thanks for the quick reply. That's useful to know.