github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/util/osutil/osfs.go (about) 1 package osutil 2 3 import ( 4 "io/fs" 5 "os" 6 ) 7 8 // FS implements [fs.FS], [fs.StatFS], and [fs.ReadFileFS] 9 // using package [os]. 10 // 11 // This filesystem does not respect [fs.ValidPath] rules, 12 // and fails [testing/fstest.TestFS]! 13 // 14 // Still, it can be a useful tool to unify implementations 15 // that can access either the [os] filesystem or an [fs.FS]. 16 // It's OK to use this to open files, but you should avoid 17 // opening directories, resolving paths, or walking the file system. 18 type FS struct{} 19 20 // Open implements [fs.FS]. 21 func (FS) Open(name string) (fs.File, error) { 22 return OpenFile(name, os.O_RDONLY, 0) 23 } 24 25 // ReadFileFS implements [fs.StatFS]. 26 func (FS) Stat(name string) (fs.FileInfo, error) { 27 return os.Stat(name) 28 } 29 30 // ReadFile implements [fs.ReadFileFS]. 31 func (FS) ReadFile(name string) ([]byte, error) { 32 return os.ReadFile(name) 33 }