ITADN

Not clear how to use ArrayBuffer backend with Emscripten FS

#268Openvitonsky 创建于 2025-10-06
V
vitonskycommented
Hi, I want to mount `ArrayBuffer` FS on Emscripten FS? ## My use case I use https://pglite.dev/ and want to keep FS in RAM, but dump this FS as `ArrayBuffer` once changes occurs. PGLite have method https://pglite.dev/docs/api#dumpdatadir that even with no compression takes 100ms and this is too long time, since data dump may be called frequently. Since PGLite uses a MEMFS i think the problem is they iterate whole FS content to build archive every time we call dump. As potential solution I see a FS that will store data in single `ArrayBuffer` and will let us dump this buffer immediately (only time to copy buffer). It looks your package implements exactly I need ```ts import { configureSingle, fs, SingleBuffer } from "@zenfs/core"; const sharedArrayBuffer = new ArrayBuffer(100000); await configureSingle({ backend: SingleBuffer, buffer: sharedArrayBuffer, }); fs.writeFileSync('/test.txt', 'You can do this anywhere, including browsers!'); ``` ## The problem So my goal is to - Create SingleBuffer FS - Mount this FS as emscripten FS at specific path `/tmp/pglite/base` - Ensure that if i save buffer in FS, and then load it in another session and will init a SingleBuffer FS with that, i will have the same content (paths and files) with the same properties (time and access flags) I just read the docs of https://www.npmjs.com/package/@zenfs/emscripten and docs of `core` and can't understand how to do it. I see how to create SingleBuffer FS, and I see i can do like that ``` await configureSingle({ backend: Emscripten, FS: FS }); ``` but it's not clear how to mount SingleBuffer FS on EMFS at specific path. Maybe it's just problem with docs. Could you elaborate it
0 条评论