github.com/gaukas/wazerofs@v0.1.0/README.md (about)

     1  # wazerofs
     2  Helper tools for custom Wazero FS
     3  
     4  Forked from [karelbilek/wazero-fs-tools](https://github.com/karelbilek/wazero-fs-tools) for experimental purposes.
     5  
     6  Go doc: https://pkg.go.dev/github.com/karelbilek/wazero-fs-tools
     7  
     8  ## memfs
     9  
    10  MemFS is a in-memory filesystem. Note that minimal amount of functionality is actually done;
    11  feel free to add a PR.
    12  
    13  The actual underlying implementation is github.com/blang/vfs/memfs.
    14  Here it's just a tiny wrapper around it.
    15  
    16  github.com/blang/vfs/memfs seems to be no longer maintained, so if there is some issue, I can eventually
    17  subtree it here; but I don't think it's necessary for now.
    18  
    19  ## sysfs
    20  
    21  SysFS is just a verbatim copy of wazero internal sysfs. Useful for mixing with wraplogfs.
    22  
    23  Do NOT use it in real-life code, because it is not being kept up-to-date with wazero; use it only for experimenting/debugging.
    24  
    25  ## wraplogfs
    26  
    27  WrapLogFS is a wrapper around existing filesystem that logs all inputs/outputs
    28  
    29  # Example - log FS
    30  
    31  ```go
    32  import (
    33      "github.com/tetratelabs/wazero"
    34      // note: either this or wazero-fs-tools/sysfs needs to be renamed in import
    35      expsysfs "github.com/tetratelabs/wazero/experimental/sysfs"
    36      
    37      "github.com/gaukas/wazerofs/sysfs"
    38      "github.com/gaukas/wazerofs/wraplogfs"
    39  )
    40  
    41  // ...
    42  func main() {
    43      rootFS := sysfs.DirFS("/")
    44      wrappedFS := wraplogfs.New(rootFS, os.Stdout, false, "root fs")
    45  
    46      fsConfig := wazero.NewFSConfig()
    47      fsConfig = fsConfig.(expsysfs.FSConfig).WithSysFSMount(wrappedFS, "/") 
    48      // now all / file operations will be logged
    49  
    50      moduleConfig := wazero.NewModuleConfig().WithFSConfig(fsConfig)./*...*/
    51  }
    52  ```
    53  
    54  # Example - memory FS
    55  
    56  ```go
    57  import (
    58      "log"
    59  
    60      "github.com/tetratelabs/wazero"
    61      expsysfs "github.com/tetratelabs/wazero/experimental/sysfs"
    62      
    63      "github.com/gaukas/wazerofs/memfs"
    64  )
    65  
    66  // ...
    67  func main() {
    68      memFS := memfs.New()
    69  
    70      // can write some files for start
    71      err := rootFS.WriteFile("tmp/foo.txt", []byte("this is content"))
    72      if err != nil {
    73          log.Fatal(err)
    74      }
    75  
    76      fsConfig := wazero.NewFSConfig()
    77      fsConfig = fsConfig.(expsysfs.FSConfig).WithSysFSMount(memFS, "/") 
    78      // all now happens in memory
    79  }
    80  ```