package writefs

import "github.com/tetratelabs/wazero/experimental/writefs"

Package writefs includes wazero-specific fs.FS implementations that allow creation and deletion of files and directories.

This is a work-in-progress and a workaround needed because write support is not yet supported in fs.FS. See https://github.com/golang/go/issues/45757

Tracking issue: https://github.com/tetratelabs/wazero/issues/390

Example (DirFS)

This shows how to use writefs.DirFS to map paths relative to "/work/appA", as "/". Unlike os.DirFS, these paths will be writable.

Code:play 

package main

import (
	_ "embed"
	"log"

	"github.com/tetratelabs/wazero"
	"github.com/tetratelabs/wazero/experimental/writefs"
)

var config wazero.ModuleConfig //nolint

// This shows how to use writefs.DirFS to map paths relative to "/work/appA",
// as "/". Unlike os.DirFS, these paths will be writable.
func main() {
	fs, err := writefs.NewDirFS("/work/appA")
	if err != nil {
		log.Panicln(err)
	}
	config = wazero.NewModuleConfig().WithFS(fs)
}

Index

Examples

Functions

func NewDirFS

func NewDirFS(dir string) (fs.FS, error)

NewDirFS creates a writeable filesystem at the given path on the host filesystem.

This is like os.DirFS, but allows creation and deletion of files and directories, as well as timestamp modifications. None of which are supported in fs.FS.

The following errors are expected:

Isolation

Symbolic links can escape the root path as files are opened via os.OpenFile which cannot restrict following them.

This is wazero-only

Do not attempt to use the result as a fs.FS, as it will panic. This is a bridge to a future filesystem abstraction made for wazero.

Source Files

writefs.go

Version
v1.0.0-pre.7
Published
Jan 2, 2023
Platform
linux/amd64
Imports
2 packages
Last checked
1 hour ago

Tools for package owners.