github.com/3JoB/vfs@v1.0.0/os.go (about) 1 package vfs 2 3 import ( 4 "io/ioutil" 5 "os" 6 ) 7 8 // OsFS represents a filesystem backed by the filesystem of the underlying OS. 9 type OsFS struct{} 10 11 // OS returns a filesystem backed by the filesystem of the os. It wraps os.* stdlib operations. 12 func OS() *OsFS { 13 return &OsFS{} 14 } 15 16 // PathSeparator returns the path separator 17 func (fs OsFS) PathSeparator() uint8 { 18 return os.PathSeparator 19 } 20 21 // Open wraps os.Open 22 func (fs OsFS) Open(name string) (File, error) { 23 return os.Open(name) 24 } 25 26 // OpenFile wraps os.OpenFile 27 func (fs OsFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) { 28 return os.OpenFile(name, flag, perm) 29 } 30 31 // Remove wraps os.Remove 32 func (fs OsFS) Remove(name string) error { 33 return os.Remove(name) 34 } 35 36 // RemoveAll removes path and any children it contains. 37 // It removes everything it can but returns the first error 38 // it encounters. If the path does not exist, RemoveAll 39 // returns nil (no error). 40 // If there is an error, it will be of type *PathError. 41 func (fs OsFS) RemoveAll(name string) error { 42 return os.RemoveAll(name) 43 } 44 45 // Mkdir wraps os.Mkdir 46 func (fs OsFS) Mkdir(name string, perm os.FileMode) error { 47 return os.Mkdir(name, perm) 48 } 49 50 // Symlink wraps os.Symlink 51 func (fs OsFS) Symlink(oldname, newname string) error { 52 return os.Symlink(oldname, newname) 53 } 54 55 // Rename wraps os.Rename 56 func (fs OsFS) Rename(oldpath, newpath string) error { 57 return os.Rename(oldpath, newpath) 58 } 59 60 // Stat wraps os.Stat 61 func (fs OsFS) Stat(name string) (os.FileInfo, error) { 62 return os.Stat(name) 63 } 64 65 // Lstat wraps os.Lstat 66 func (fs OsFS) Lstat(name string) (os.FileInfo, error) { 67 return os.Lstat(name) 68 } 69 70 // ReadDir wraps ioutil.ReadDir 71 func (fs OsFS) ReadDir(path string) ([]os.FileInfo, error) { 72 return ioutil.ReadDir(path) 73 }