all: require Go-1.19
all: first import
overlayfs
is a simple package to overlay io/fs.FS values for Go.
func ExampleFrom() {
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"
}```
## License
- `overlayfs` is released under the `BSD-3` license.