-
Hey, I am currently trying to mount the in-memory fs to a web-worker. I would like to access the whole fs ( // worker.ts
// mount remote fs
await configure({
mounts: {
'/': await resolveRemoteMount(self, { backend: InMemory, name: 'tmp' }),
},
});
console.log(await fs.promises.readFile('/etc/os-release', 'utf8')); // main.ts
const worker = new Worker(new URL('./worker/index.mjs', import.meta.url), {
/* @vite-ignore */
name: workerName,
type: 'module',
});
const root = this.fs.mounts.get('/');
if (!root) {
throw new Error('No root FS found');
}
attachFS(worker, root); I've checked https://github.com/zen-fs/core/blob/main/src/backends/port/readme.md and issues like https://github.com/orgs/zen-fs/discussions/107 and still can't get it to work. There are quite a few options in the docs / code 😅 Maybe some naming / behavior similar to how I would mount a nfs-share to my linux system would be helpful. Some general questions:
Would love to add some details to the docs when I understand the flow correctly if that is welcome and would help others. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for asking. If you'd like to use the FS inside the worker, you can switch the code from the example in the port readme: worker.ts import { configureSingle, fs } from '@zenfs/core';
import { Port } from '@zenfs/port';
await configureSingle({
backend: Port,
port: self,
});
fs.writeFileSync('example.txt', 'This will be written to the fs on the main thread!'); main.ts import { InMemory, resolveRemoteMount, attachFS } from '@zenfs/core';
const worker = new Worker('worker.js');
await resolveRemoteMount(worker, { backend: InMemory, name: 'tmp' }); To answer your other questions:
This exposes a file system on the given port. In addition to resolving the mount configuration, it also handles packets received before the backend is ready.
I hope I've been able to answer your questions, please let me know if you need any more help. |
Beta Was this translation helpful? Give feedback.
@anbraten,
Thanks for asking. If you'd like to use the FS inside the worker, you can switch the code from the example in the port readme:
worker.ts
main.ts
To answer your other questions: