Documentation ¶
Index ¶
- Constants
- func HasOpenFlagRead(flag int) bool
- func HasOpenFlagWrite(flag int) bool
- 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 ¶
View Source
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 ¶
Types ¶
type DirEntry ¶
type DirEntry = filesystem.DirEntry
type File ¶
type File = filesystem.File
type FileInfo ¶
type FileInfo = filesystem.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/ports/filesystem" "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 := filesystem.Create(fsys, file2Name) if err != nil { panic(err) } file2.Close() file2, err = filesystem.Open(fsys, file2Name) if err != nil { panic(err) } file2.Close() filesystem.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/ports/filesystem" "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 := filesystem.Create(fsys, file2Name) if err != nil { panic(err) } file2.Close() file2, err = filesystem.Open(fsys, file2Name) if err != nil { panic(err) } file2.Close() filesystem.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
Click to show internal directories.
Click to hide internal directories.