filesystem

package
v0.296.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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 HasOpenFlagRead(flag int) bool

func HasOpenFlagWrite

func HasOpenFlagWrite(flag int) bool

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.

Example
package main

import (
	"go.llib.dev/frameless/adapter/memory"

	"go.llib.dev/frameless/port/filesystem"
)

func main() {
	var fsys filesystem.FileSystem = &memory.FileSystem{}

	files, err := filesystem.ReadDir(fsys, "testdir")
	if err != nil {
		panic(err)
	}
	_ = files
}
Output:

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.

Example
package main

import (
	"io/fs"

	"go.llib.dev/frameless/adapter/memory"

	"go.llib.dev/frameless/port/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 DirEntry

type DirEntry struct {
	FileInfo fs.FileInfo
}

func (DirEntry) Info

func (de DirEntry) Info() (fs.FileInfo, error)

func (DirEntry) IsDir

func (de DirEntry) IsDir() bool

func (DirEntry) Name

func (de DirEntry) Name() string

func (DirEntry) Type

func (de DirEntry) Type() fs.FileMode

type File

type File interface {
	io.Closer
	io.Reader
	io.Writer
	io.Seeker
	fs.File
	fs.ReadDirFile
}

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.

Example
package main

import (
	"go.llib.dev/frameless/adapter/memory"

	"go.llib.dev/frameless/port/filesystem"
)

func main() {
	var fsys filesystem.FileSystem = &memory.FileSystem{}

	file, err := filesystem.Create(fsys, "testfile")
	if err != nil {
		panic(err)
	}
	_ = file
}
Output:

func Open

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 (
	"go.llib.dev/frameless/adapter/memory"

	"go.llib.dev/frameless/port/filesystem"
)

func main() {
	var fsys filesystem.FileSystem = &memory.FileSystem{}

	file, err := filesystem.Open(fsys, "testfile")
	if err != nil {
		panic(err)
	}
	_ = file
}
Output:

type FileInfo

type FileInfo struct {
	Path        string
	FileSize    int64
	FileMode    fs.FileMode
	ModifiedAt  time.Time
	IsDirectory bool
	System      any
}

func (FileInfo) IsDir

func (fi FileInfo) IsDir() bool

func (FileInfo) ModTime

func (fi FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (fi FileInfo) Mode() fs.FileMode

func (FileInfo) Name

func (fi FileInfo) Name() string

func (FileInfo) Size

func (fi FileInfo) Size() int64

func (FileInfo) Sys

func (fi FileInfo) Sys() any

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 |
+------------+------+-------+

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL