Documentation ¶
Index ¶
- Variables
- func IfExists(path string) bool
- func IsDir(path string) (bool, error)
- func IsRegularFile(path string) (bool, error)
- type FileSystemOperator
- func (fs *FileSystemOperator) CreateDir(path string) error
- func (fs *FileSystemOperator) CreateFile(path string, content []byte) error
- func (fs *FileSystemOperator) DeleteDir(path string) error
- func (fs *FileSystemOperator) DeleteFile(path string) error
- func (fs *FileSystemOperator) List(rootDir string, mode ListMode, isRecursive bool) ([]string, error)
- func (fs *FileSystemOperator) Read(path string) ([]byte, error)
- func (fs *FileSystemOperator) Rename(oldPath string, newPath string) error
- func (fs *FileSystemOperator) Write(path string, content []byte) error
- type ListMode
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsRegularFile ¶
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.