Documentation ¶
Index ¶
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 ¶ added in v0.121.0
func HasOpenFlagWrite ¶ added in v0.121.0
func ReadDir ¶ added in v0.78.0
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.
Example ¶
package main import ( "github.com/adamluzsi/frameless/adapters/memory" "github.com/adamluzsi/frameless/ports/filesystem" ) func main() { var fsys filesystem.FileSystem = &memory.FileSystem{} files, err := filesystem.ReadDir(fsys, "testdir") if err != nil { panic(err) } _ = files }
Output:
func WalkDir ¶ added in v0.78.0
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.
Example ¶
package main import ( "github.com/adamluzsi/frameless/adapters/memory" "io/fs" "github.com/adamluzsi/frameless/ports/filesystem" ) func main() { var fsys filesystem.FileSystem = &memory.FileSystem{} _ = filesystem.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { return fs.SkipDir }) }
Output:
Types ¶
type File ¶
func Create ¶ added in v0.78.0
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.
Example ¶
package main import ( "github.com/adamluzsi/frameless/adapters/memory" "github.com/adamluzsi/frameless/ports/filesystem" ) func main() { var fsys filesystem.FileSystem = &memory.FileSystem{} file, err := filesystem.Create(fsys, "testfile") if err != nil { panic(err) } _ = file }
Output:
func Open ¶ added in v0.78.0
func Open(fsys FileSystem, name string) (File, error)
Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has FileMode O_RDONLY. If there is an error, it will be of type *PathError.
Example ¶
package main import ( "github.com/adamluzsi/frameless/adapters/memory" "github.com/adamluzsi/frameless/ports/filesystem" ) func main() { var fsys filesystem.FileSystem = &memory.FileSystem{} file, err := filesystem.Open(fsys, "testfile") if err != nil { panic(err) } _ = file }
Output:
type FileInfo ¶ added in v0.78.0
type FileSystem ¶
type FileSystem interface { // Stat returns a FileInfo describing the named file. // If there is an error, it will be of type *PathError. Stat(name string) (fs.FileInfo, error) // OpenFile is the generalized open call; most users will use Open // or Create instead. It opens the named file with specified flag // (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag // is passed, it is created with mode perm (before umask). If successful, // methods on the returned File can be used for I/O. // If there is an error, it will be of type *PathError. OpenFile(name string, flag int, perm fs.FileMode) (File, error) // Mkdir creates a new directory with the specified name and permission // bits (before umask). // If there is an error, it will be of type *PathError. Mkdir(name string, perm fs.FileMode) error // Remove removes the named file or (empty) directory. // If there is an error, it will be of type *PathError. Remove(name string) error }
FileSystem is a header interface for representing a file-system.
permission cheat sheet:
+-----+---+--------------------------+ | rwx | 7 | Read, write and execute | | rw- | 6 | Read, write | | r-x | 5 | Read, and execute | | r-- | 4 | Read, | | -wx | 3 | Write and execute | | -w- | 2 | Write | | --x | 1 | Execute | | --- | 0 | no permissions | +------------------------------------+ +------------+------+-------+ | Permission | Octal| Field | +------------+------+-------+ | rwx------ | 0700 | User | | ---rwx--- | 0070 | Group | | ------rwx | 0007 | Other | +------------+------+-------+