Debian Codegraph @

example_test.go

raw
1 package memfs_test
2
3 import (
4 "fmt"
5 "io/fs"
6
7 "github.com/psanford/memfs"
8 )
9
10 func ExampleNew() {
11 rootFS := memfs.New()
12
13 err := rootFS.MkdirAll("dir1/dir2", 0777)
14 if err != nil {
15 panic(err)
16 }
17
18 err = rootFS.WriteFile("dir1/dir2/f1.txt", []byte("incinerating-unsubstantial"), 0755)
19 if err != nil {
20 panic(err)
21 }
22
23 err = fs.WalkDir(rootFS, ".", func(path string, d fs.DirEntry, err error) error {
24 fmt.Println(path)
25 return nil
26 })
27 if err != nil {
28 panic(err)
29 }
30
31 content, err := fs.ReadFile(rootFS, "dir1/dir2/f1.txt")
32 if err != nil {
33 panic(err)
34 }
35 fmt.Printf("%s\n", content)
36 }