zen-fs / core

A filesystem, anywhere.
https://zenfs.dev/core/
MIT License
134 stars 20 forks source link

Option to not use sync cache with `Async(FileSystem)` #64

Closed atty303 closed 5 months ago

atty303 commented 5 months ago

I've decided to use only the Async API in my integration with Emscripten, so I no longer need crossCopy when using Async(FileSystem). I thought it would be nice to have an option to not use crossCopy or the memory mirror itself in such cases.

james-pre commented 5 months ago

The idea behind having all async file systems use Async, and the sync. cache, is that fs.*Sync work no matter what. Perhaps a top-level configuration option would be best:

await configure({
    disableAsyncCache: true,
    mounts: {
        ...
    }
})

What do you think?

james-pre commented 5 months ago

Like https://github.com/zen-fs/dom/issues/12, this could be done using FileSystemMetadata. That would be more flexible.

james-pre commented 5 months ago

@atty303 Does v0.12.1 resolve the issue?

You should be able to set disableAsyncCache per backend and overall:

await configure({
    disableAsyncCache: true,
    mounts: {
        // this mount will have the sync cache
        '/mnt/net/example': {
            backend: Fetch,
            index: 'https://example.com/index.json',
            disableAsyncCache: false, 
        },
        // this mount will not have the sync cache
        '/mnt/emscripten': { backend: Emscripten, /* Should be published soon */ },
        // this mount will not have the sync cache
        '/mnt/worker/0': { backend: Port, port: worker0 },
        // this mount will not have the sync cache
        '/mnt/worker/1': { backend: Port, port: worker1 },
    }
});
james-pre commented 5 months ago

Unit tests confirm that this is working correctly, so I am closing the issue.

atty303 commented 5 months ago

Sorry for the delay. My app requires ZipFS to start and ZipFS is not yet synced with 0.12.1 so I cannot check. So we will wait for the ZipFS update. Thank you in advance for your help.

james-pre commented 5 months ago

@atty303 My apologies, I had not released the Zip updates yet. @zenfs/zip v0.4.0 should be up to date.