https://github.com/psanford/memfs
In-memory implementation of Go's `io/fs.FS` interface
https://github.com/psanford/memfs
go
Last synced: about 1 year ago
JSON representation
In-memory implementation of Go's `io/fs.FS` interface
- Host: GitHub
- URL: https://github.com/psanford/memfs
- Owner: psanford
- License: bsd-3-clause
- Created: 2021-01-08T04:37:18.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-19T19:17:26.000Z (over 1 year ago)
- Last Synced: 2025-04-12T15:57:57.832Z (about 1 year ago)
- Topics: go
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 113
- Watchers: 3
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# memfs: A simple in-memory io/fs.FS filesystem
memfs is an in-memory implementation of Go's io/fs.FS interface.
The goal is to make it easy and quick to build an fs.FS filesystem
when you don't have any complex requirements.
Documentation: https://pkg.go.dev/github.com/psanford/memfs
`io/fs` docs: https://tip.golang.org/pkg/io/fs/
## Usage
```
package main
import (
"fmt"
"io/fs"
"github.com/psanford/memfs"
)
func main() {
rootFS := memfs.New()
err := rootFS.MkdirAll("dir1/dir2", 0777)
if err != nil {
panic(err)
}
err = rootFS.WriteFile("dir1/dir2/f1.txt", []byte("incinerating-unsubstantial"), 0755)
if err != nil {
panic(err)
}
err = fs.WalkDir(rootFS, ".", func(path string, d fs.DirEntry, err error) error {
fmt.Println(path)
return nil
})
if err != nil {
panic(err)
}
content, err := fs.ReadFile(rootFS, "dir1/dir2/f1.txt")
if err != nil {
panic(err)
}
fmt.Printf("%s\n", content)
}
```