fs

package
v1.4.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsNotDir    = errors.New("the path is not a directory")
	ErrIsNotFile   = errors.New("the path is not a regular file")
	ErrExists      = errors.New("path has already existed")
	ErrNotExists   = errors.New("path does not exist")
	ErrInvalidPath = errors.New("invalid path")
)

Functions

func IfExists

func IfExists(path string) bool

func IsDir

func IsDir(path string) (bool, error)

func IsRegularFile

func IsRegularFile(path string) (bool, error)

Types

type FileSystemOperator

type FileSystemOperator struct{}

func (*FileSystemOperator) CreateDir

func (fs *FileSystemOperator) CreateDir(path string) error

CreateDir will create the dir at path. If the parent dir of this path does not exist, it will be created first. If the path has already existed and is not dir, return ErrIsNotDir. If the path has already existed and is a dir, return ErrExists.

func (*FileSystemOperator) CreateFile

func (fs *FileSystemOperator) CreateFile(path string, content []byte) error

CreateFile will create the file at path with content. If its parent dir does not exist, it will be created first. If the path has already existed and is not regular file, return ErrIsNotFile. If the path has already existed and is regular file, return ErrExists.

func (*FileSystemOperator) DeleteDir

func (fs *FileSystemOperator) DeleteDir(path string) error

DeleteDir will delete directory at path. All files and subdirs will be deleted. If the path does not exist, do nothing. If the path does not a directory, return ErrIsNotDir.

func (*FileSystemOperator) DeleteFile

func (fs *FileSystemOperator) DeleteFile(path string) error

DeleteFile will delete file at path. If the path does not exist, do nothing. If the path exists but is not a regular file, return ErrIsNotFile.

func (*FileSystemOperator) List

func (fs *FileSystemOperator) List(rootDir string, mode ListMode, isRecursive bool) ([]string, error)

list will list names of entries under the rootDir(except the root dir). If isRecurisive is set, it will walk the path including all subdirs. The returned file names are absolute paths and in lexicographical order. There're two modes: "dirs" returns names of all directories. "files" returns names of all regular files.

If the path does not exist, return ErrNotExists. If the path is not a directory, return ErrIsNotDir. If the rootDir exists but has no entry, return a empty slice and nil error.

func (*FileSystemOperator) Read

func (fs *FileSystemOperator) Read(path string) ([]byte, error)

Read will read the file at path. If the path does not exist, ErrNotExists will be returned. If the path is not a regular file, ErrIsNotFile will be returned.

func (*FileSystemOperator) Rename

func (fs *FileSystemOperator) Rename(oldPath string, newPath string) error

Rename will rename file(or directory) at oldPath as newPath. If file of newPath has already existed, it will be replaced. If path does not exists, return ErrNotExists. If oldPath and newPath does not under the same parent dir, return ErrInvalidPath.

func (*FileSystemOperator) Write

func (fs *FileSystemOperator) Write(path string, content []byte) error

Write will write the content at path. If the path does not exist, return ErrNotExists. If the path is not a regular file, return ErrIsNotFile.

type ListMode

type ListMode string
var (
	ListModeDirs  ListMode = "dirs"
	ListModeFiles ListMode = "files"
)

Jump to

Keyboard shortcuts

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