Documentation
¶
Overview ¶
Package overlyafs provides a way to overlay multiple fs.FS.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS overlays multiple fs.FS.
func From ¶
From creates a new overlay fs from the provided stack of FS. FS contents are considered in the reverse order of the provided slice. ie: the last stacked layer wins.
Example ¶
package main import ( "fmt" "io/fs" "log" "testing/fstest" "git.sr.ht/~sbinet/overlayfs" ) func main() { fs1 := fstest.MapFS{ "dir1/dir00": &fstest.MapFile{ Mode: fs.ModeDir, }, "dir1/dir11/f111.txt": &fstest.MapFile{ Data: []byte(`hello 1`), Mode: 0644, }, "dir1/dir11/f112.txt": &fstest.MapFile{ Data: []byte(`hello 2`), Mode: 0644, }, } fs2 := fstest.MapFS{ "dir1/dir22": &fstest.MapFile{ Mode: fs.ModeDir, }, "dir1/dir11/f111.txt": &fstest.MapFile{ Data: []byte(`hello 1 from f2`), Mode: 0644, }, "dir1/dir11/f113.txt": &fstest.MapFile{ Data: []byte(`hello 3`), Mode: 0644, }, } ovfs := overlayfs.From(fs1, fs2) f1, err := fs.ReadFile(ovfs, "dir1/dir11/f111.txt") if err != nil { log.Fatalf("could not read file: %v", err) } fmt.Printf("f1: %q\n", f1) f2, err := fs.ReadFile(ovfs, "dir1/dir11/f112.txt") if err != nil { log.Fatalf("could not read file: %v", err) } fmt.Printf("f2: %q\n", f2) f3, err := fs.ReadFile(ovfs, "dir1/dir11/f113.txt") if err != nil { log.Fatalf("could not read file: %v", err) } fmt.Printf("f3: %q\n", f3) }
Output: f1: "hello 1 from f2" f2: "hello 2" f3: "hello 3"
Click to show internal directories.
Click to hide internal directories.