wa-lang.org/wazero@v1.0.2/experimental/fs.go (about)

     1  package experimental
     2  
     3  import (
     4  	"context"
     5  	"io/fs"
     6  
     7  	"wa-lang.org/wazero/api"
     8  	internalfs "wa-lang.org/wazero/internal/sys"
     9  )
    10  
    11  // WithFS overrides fs.FS in the context-based manner. Caller needs to take
    12  // responsibility for closing the filesystem.
    13  //
    14  // Note: This has the same effect as the same function on wazero.ModuleConfig.
    15  func WithFS(ctx context.Context, fs fs.FS) (context.Context, api.Closer) {
    16  	if fs == nil {
    17  		fs = internalfs.EmptyFS
    18  	}
    19  	fsCtx := internalfs.NewFSContext(fs)
    20  	return context.WithValue(ctx, internalfs.FSKey{}, fsCtx), fsCtx
    21  }