Skip to content

Mounting page fs to web worker #140

Closed Answered by james-pre
anbraten asked this question in Q&A
Discussion options

You must be logged in to vote

@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

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:

await resolveRemoteMount(self, { backend: InMemory, name: 'tmp' }); would create a in-memory …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by james-pre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants