Documentation ¶
Overview ¶
Package osfs provides a filesystem for the OS.
Index ¶
- func DirFS(dir string) fs.FS
- type OSFS
- func (fsys *OSFS) CreateFile(name string, mode fs.FileMode) (wfs.WriterFile, error)
- func (fsys *OSFS) Glob(pattern string) ([]string, error)
- func (fsys *OSFS) MkdirAll(dir string, mode fs.FileMode) error
- func (fsys *OSFS) Open(name string) (fs.File, error)
- func (fsys *OSFS) ReadDir(dir string) ([]fs.DirEntry, error)
- func (fsys *OSFS) ReadFile(name string) ([]byte, error)
- func (fsys *OSFS) RemoveAll(path string) error
- func (fsys *OSFS) RemoveFile(name string) error
- func (fsys *OSFS) Stat(name string) (fs.FileInfo, error)
- func (fsys *OSFS) Sub(dir string) (fs.FS, error)
- func (fsys *OSFS) WriteFile(name string, p []byte, mode fs.FileMode) (int, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirFS ¶
DirFS returns a filesystem for the tree of files rooted at the directory dir. The filesystem can write using wfs.WriteFile(fsys fs.FS, name string, p []byte).
Example ¶
package main import ( "fmt" "io/fs" "io/ioutil" "log" "os" "github.com/jarxorg/wfs" "github.com/jarxorg/wfs/osfs" ) func main() { tmpDir, err := ioutil.TempDir("", "example") if err != nil { log.Fatal(err) } defer os.RemoveAll(tmpDir) name := "example.txt" content := []byte(`Hello`) fsys := osfs.DirFS(tmpDir) _, err = wfs.WriteFile(fsys, name, content, fs.ModePerm) if err != nil { log.Fatal(err) } wrote, err := ioutil.ReadFile(tmpDir + "/" + name) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", string(wrote)) }
Output: Hello
Types ¶
type OSFS ¶
type OSFS struct { Dir string // contains filtered or unexported fields }
OSFS represents a filesystem for the OS.
func NewOSFS ¶
NewOSFS returns a filesystem for the tree of files rooted at the directory dir. Deprecated: Use New.
func (*OSFS) CreateFile ¶
CreateFile creates the named file.
func (*OSFS) Glob ¶
Glob returns the names of all files matching pattern, providing an implementation of the top-level Glob function.
func (*OSFS) ReadDir ¶
ReadDir reads the named directory and returns a list of directory entries sorted by filename.
func (*OSFS) RemoveFile ¶
RemoveFile removes the specified named file.
func (*OSFS) Stat ¶
Stat returns a FileInfo describing the file. If there is an error, it should be of type *PathError.