Files
sqlite3/util/osutil/osfs.go

42 lines
1.1 KiB
Go
Raw Normal View History

2025-03-26 02:13:30 +00:00
// Package osutil implements operating system utilities.
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) {
2025-03-26 02:13:30 +00:00
return os.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)
}
2025-03-26 02:13:30 +00:00
// OpenFile behaves the same as [os.OpenFile].
//
// Deprecated: use os.OpenFile instead.
func OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
return os.OpenFile(name, flag, perm)
}