Files
wazero/experimental/fs.go
Crypt Keeper 798ff20f81 Removes WithWorkDirFS and "." resolution (#660)
This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.

This also allows experimental.WithFS to block file access via passing nil.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-27 13:29:35 +08:00

22 lines
578 B
Go

package experimental
import (
"context"
"io/fs"
"github.com/tetratelabs/wazero/api"
internalfs "github.com/tetratelabs/wazero/internal/sys"
)
// WithFS overrides fs.FS in the context-based manner. Caller needs to take
// responsibility for closing the filesystem.
//
// Note: This has the same effect as the same function on wazero.ModuleConfig.
func WithFS(ctx context.Context, fs fs.FS) (context.Context, api.Closer) {
if fs == nil {
fs = internalfs.EmptyFS
}
fsCtx := internalfs.NewFSContext(fs)
return context.WithValue(ctx, internalfs.FSKey{}, fsCtx), fsCtx
}