Files
sqlite3/util/osutil/osfs.go

34 lines
842 B
Go
Raw Normal View History

2024-01-03 12:47:49 +00:00
package osutil
2024-01-03 00:54:30 +00:00
import (
"io/fs"
"os"
)
2024-01-03 12:47:49 +00:00
// FS implements [fs.FS], [fs.StatFS], and [fs.ReadFileFS]
2024-01-03 00:54:30 +00:00
// using package [os].
//
// This filesystem does not respect [fs.ValidPath] rules,
// and fails [testing/fstest.TestFS]!
//
// Still, it can be a useful tool to unify implementations
// that can access either the [os] filesystem or an [fs.FS].
// It's OK to use this to open files, but you should avoid
// opening directories, resolving paths, or walking the file system.
2024-01-03 12:47:49 +00:00
type FS struct{}
2024-01-03 00:54:30 +00:00
// Open implements [fs.FS].
2024-01-03 12:47:49 +00:00
func (FS) Open(name string) (fs.File, error) {
return OpenFile(name, os.O_RDONLY, 0)
2024-01-03 00:54:30 +00:00
}
// ReadFileFS implements [fs.StatFS].
2024-01-03 12:47:49 +00:00
func (FS) Stat(name string) (fs.FileInfo, error) {
2024-01-03 00:54:30 +00:00
return os.Stat(name)
}
// ReadFile implements [fs.ReadFileFS].
2024-01-03 12:47:49 +00:00
func (FS) ReadFile(name string) ([]byte, error) {
2024-01-03 00:54:30 +00:00
return os.ReadFile(name)
}