filesystem

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDir

func ReadDir(fs Fser, dirname string) ([]os.FileInfo, error)

func ReadFile

func ReadFile(fs Fser, filename string) ([]byte, error)

func WriteFile

func WriteFile(fs Fser, filename string, data []byte, perm os.FileMode) error

Types

type FileSystem

type FileSystem struct {
	Fser
}

func NewFileSystem

func NewFileSystem() *FileSystem

func (FileSystem) ReadDir

func (f FileSystem) ReadDir(dirname string) ([]os.FileInfo, error)

func (FileSystem) ReadFile

func (f FileSystem) ReadFile(filename string) ([]byte, error)

ReadFile reads context of the file identified filename. returns err == nil if successful, or err == EOF. Because ReadFile reads the whole file, do not try reading very large file

func (FileSystem) WriteFile

func (f FileSystem) WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes data to teh file identified filename. If the file is not existed, will create a file named filename with permission perm

type Filer

type Filer interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	io.WriterAt

	Name() string
	Stat() (os.FileInfo, error)
	WriteString(s string) (ret int, err error)
}

Filer is a interface, represent a file in filesystem

type Fser

type Fser interface {
	// Create create a file, returning the filer and an error, if any happens
	Create(name string) (Filer, error)

	// Mkdir create a directory, return error is any happens
	Mkdir(name string, perm os.FileMode) error

	// Open opens a file, returning the filer and an error, if any happens
	Open(name string) (Filer, error)

	// OpenFile opens a file using the given flags and the given filemode, returning
	// the filer and an error, if any happens
	OpenFile(name string, flag int, perm os.FileMode) (Filer, error)

	// Remove removes a file identified name, returning an error if any happens
	// It doest not fail if the path does not exist(return nil)
	Remove(name string) error

	// RemoveAll removes a directory path and any children it contains. It doest
	// not fail if the path does not exist(return nil)
	RemoveAll(path string) error

	// Rename renames a file name, returning an error if any happens
	Rename(oldname, newname string) error

	// Stat returns an FileInfo describing the identified name, or an error if any happen
	Stat(name string) (os.FileInfo, error)

	// Name returning the name of the file
	Name() string

	// Chmod changes the mode of the named file to perm(FileMode), returning an error
	// if any happens
	Chmod(name string, perm os.FileMode) error

	// Chown changes the uid and gid of the identified file, returning an error if
	// any happens
	Chown(name string, uid, gid int) error
}

Fser is the filesystem interface

type IOFile

type IOFile struct {
	Fser
}

func NewIOFile

func NewIOFile(fs Fser) IOFile

func (IOFile) Open

func (iof IOFile) Open(name string) (fs.File, error)

func (IOFile) ReadFile

func (iof IOFile) ReadFile(name string) ([]byte, error)

Jump to

Keyboard shortcuts

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