Documentation
¶
Index ¶
- Constants
- func HasOpenFlagRead(flag int) bool
- func HasOpenFlagWrite(flag int) bool
- func ReadDir(fsys FileSystem, name string) ([]fs.DirEntry, error)
- func WalkDir(fsys FileSystem, root string, fn fs.WalkDirFunc) error
- type DirEntry
- type File
- type FileInfo
- type FileSystem
- type Local
- type Memory
- type MemoryFile
- func (f *MemoryFile) Close() error
- func (f *MemoryFile) Read(bytes []byte) (int, error)
- func (f *MemoryFile) ReadDir(n int) ([]fs.DirEntry, error)
- func (f *MemoryFile) Seek(offset int64, whence int) (int64, error)
- func (f *MemoryFile) Stat() (fs.FileInfo, error)
- func (f *MemoryFile) Sync() error
- func (f *MemoryFile) Write(p []byte) (n int, err error)
Examples ¶
Constants ¶
const ( ModeUserR = modeRead << modeUserShift ModeUserW = modeWrite << modeUserShift ModeUserX = modeExec << modeUserShift ModeUserRW = ModeUserR | ModeUserW ModeUserRWX = ModeUserRW | ModeUserX ModeGroupR = modeRead << modeGroupShift ModeGroupW = modeWrite << modeGroupShift ModeGroupX = modeExec << modeGroupShift ModeGroupRW = ModeGroupR | ModeGroupW ModeGroupRWX = ModeGroupRW | ModeGroupX ModeOtherR = modeRead << modeOtherShift ModeOtherW = modeWrite << modeOtherShift ModeOtherX = modeExec << modeOtherShift ModeOtherRW = ModeOtherR | ModeOtherW ModeOtherRWX = ModeOtherRW | ModeOtherX ModeAllR = ModeUserR | ModeGroupR | ModeOtherR ModeAllW = ModeUserW | ModeGroupW | ModeOtherW ModeAllX = ModeUserX | ModeGroupX | ModeOtherX ModeAllRW = ModeAllR | ModeAllW ModeAllRWX = ModeAllRW | ModeGroupX )
Variables ¶
This section is empty.
Functions ¶
func HasOpenFlagRead ¶
func HasOpenFlagWrite ¶
func ReadDir ¶
func ReadDir(fsys FileSystem, name string) ([]fs.DirEntry, error)
ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.
func WalkDir ¶
func WalkDir(fsys FileSystem, root string, fn fs.WalkDirFunc) error
WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.
All errors that arise visiting files and directories are filtered by fn: see the fs.WalkDirFunc documentation for details.
The files are walked in lexical order, which makes the output deterministic but requires WalkDir to read an entire directory into memory before proceeding to walk that directory.
WalkDir does not follow symbolic links.
Types ¶
type File ¶
type File = filesystem.File
func Create ¶
func Create(fsys FileSystem, name string) (File, error)
Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with FileMode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has FileMode O_RDWR. If there is an error, it will be of type *PathError.
type FileInfo ¶
type FileSystem ¶
type FileSystem = filesystem.FileSystem
type Local ¶
type Local struct { // RootPath is an optional parameter to jail the file system access for file access. RootPath string }
Local provides local file system access through the frameless.FileSystem interface.
Example ¶
package main import ( "fmt" "io" "io/fs" "os" "path/filepath" "github.com/adamluzsi/frameless/adapters/filesystems" ) func main() { fsys := filesystems.Local{} file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystems.ModeUserRWX) if err != nil { panic(err) } defer file.Close() file.Write([]byte("Hello world!")) file.Seek(0, io.SeekStart) bs, err := io.ReadAll(file) if err != nil { panic(err) } fmt.Println(string(bs)) // "Hello world!" file.Close() fsys.Remove("test") fsys.Mkdir("a", filesystems.ModeUserRWX) file2Name := filepath.Join("a", "test.txt") file2, err := filesystems.Create(fsys, file2Name) if err != nil { panic(err) } file2.Close() file2, err = filesystems.Open(fsys, file2Name) if err != nil { panic(err) } file2.Close() filesystems.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { return fs.SkipDir }) }
Output:
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "fmt" "io" "io/fs" "os" "path/filepath" "github.com/adamluzsi/frameless/adapters/filesystems" ) func main() { fsys := &filesystems.Memory{} file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystems.ModeUserRWX) if err != nil { panic(err) } defer file.Close() file.Write([]byte("Hello world!")) file.Seek(0, io.SeekStart) bs, err := io.ReadAll(file) if err != nil { panic(err) } fmt.Println(string(bs)) // "Hello world!" file.Close() fsys.Remove("test") fsys.Mkdir("a", filesystems.ModeUserRWX) file2Name := filepath.Join("a", "test.txt") file2, err := filesystems.Create(fsys, file2Name) if err != nil { panic(err) } file2.Close() file2, err = filesystems.Open(fsys, file2Name) if err != nil { panic(err) } file2.Close() filesystems.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { return fs.SkipDir }) }
Output:
type MemoryFile ¶
type MemoryFile struct {
// contains filtered or unexported fields
}
func (*MemoryFile) Close ¶
func (f *MemoryFile) Close() error
func (*MemoryFile) Sync ¶
func (f *MemoryFile) Sync() error