fs

package module
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 19 Imported by: 39

README

fs - A FileSystem Abstraction System for Go

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/fs

Getting Started

f := fs.OpenFile("/path/to/file")

List of all available functions

// go doc
func BaseName(path string) string
func Chmod(name string, mode os.FileMode) error
func Chown(name string, uid, gid int) error
func Copy(srcPath, dstPath string) error
func CopyDir(srcPath string, dstPath string) error
func CopyFile(srcPath string, dstPath string) error
func CreateDir(path string) error
func CreateFile(path string) error
func CreateSymbolicLink(srcPath, dstPath string) error
func DirName(path string) string
func ExtName(path string) string
func IsAbsPath(path string) bool
func IsDir(path string) bool
func IsEmpty(path string) bool
func IsExist(path string) bool
func IsFile(path string) bool
func IsSymbolicLink(path string) bool
func JoinPath(paths ...string) string
func ListDir(path string) ([]iofs.FileInfo, error)
func Mkdir(path string) error
func Mkdirp(path string) error
func Move(srcPath, dstPath string) error
func MoveDir(srcPath string, dstPath string) error
func MoveFile(srcPath, dstPath string) error
func Open(path string) (*os.File, error)
func OpenFile(path string) (*os.File, error)
func ReadFile(srcPath string) ([]byte, error)
func ReadFileAsString(srcPath string) (string, error)
func ReadFileLines(srcPath string) ([]string, error)
func Remove(path string) error
func RemoveDir(path string) error
func RemoveFile(path string) error
func Rename(srcPath, dstPath string) error
func RenameDir(srcPath string, dstPath string) error
func RenameFile(srcPath, dstPath string) error
func Stat(path string) (os.FileInfo, error)
func TmpDirPath() string
func TmpFilePath() string
func Walk(path string, fn iofs.WalkDirFunc) error
func WalkDir(path string, fn iofs.WalkDirFunc) error
func WriteFile(path string, data []byte) error

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.3.14"

Version is the current version of the package.

Functions

func AppendFile added in v1.3.5

func AppendFile(path string, data []byte) error

AppendFile appends a file.

func BaseName

func BaseName(path string) string

BaseName returns the last element of path.

func Chmod

func Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func Chown

func Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file.

func ConfigDir added in v1.3.2

func ConfigDir() string

ConfigDir returns the config dir by user

if user is root, return system config dir
if user is common user, return user home config dir

func Copy

func Copy(srcPath, dstPath string) error

Copy copies a file or directory

func CopyDir

func CopyDir(srcPath string, dstPath string) error

CopyDir copies a directory.

func CopyFile

func CopyFile(srcPath string, dstPath string) error

CopyFile copies a file.

func CreateDir

func CreateDir(path string, perm ...iofs.FileMode) error

CreateDir creates a directory.

func CreateFile

func CreateFile(path string) (*os.File, error)

CreateFile creates a file.

func CreateSymbolicLink(srcPath, dstPath string) error

CreateSymbolicLink creates a symbolic link

func CurrentDir

func CurrentDir() string

CurrentDir returns the path of the current directory.

func DirName

func DirName(path string) string

DirName returns all but the last element of path.

func ExtName

func ExtName(path string) string

ExtName returns the file extension of path.

func ExtractTarGz added in v1.2.5

func ExtractTarGz(stream io.Reader, destDir string, logHandler func(filename string)) error

ExtractTarGz extracts a tar.gz file.

func HomeDir added in v1.3.2

func HomeDir() string

HomeDir returns the user home directory.

func IsAbsPath

func IsAbsPath(path string) bool

IsAbsPath checks whether the path is absolute.

func IsDir

func IsDir(path string) bool

IsDir checks whether the path is a directory.

func IsEmpty

func IsEmpty(path string) bool

IsEmpty checks whether the dir/file is empty.

func IsExist

func IsExist(path string) bool

IsExist checks whether a file or directory exists.

func IsFile

func IsFile(path string) bool

IsFile checks whether the path is a file.

func IsSymbolicLink(path string) bool

IsSymbolicLink checks whether the path is a symbolic link.

func JoinConfigDir added in v1.3.2

func JoinConfigDir(appName string, configName ...string) string

JoinConfigDir returns the config of appName + configName. configName default is config.yml.

func JoinCurrentDir added in v1.3.2

func JoinCurrentDir(relativePath string) string

JoinCurrentDir returns the path which relative with current dir.

func JoinHomeDir added in v1.3.2

func JoinHomeDir(relativePath string) string

JoinHomeDir returns the path which relative with homedir.

func JoinPath

func JoinPath(paths ...string) string

JoinPath joins any number of path elements into a single path, adding a

func ListDir

func ListDir(path string) ([]iofs.FileInfo, error)

ListDir lists the files in a directory.

func Merge

func Merge(filePath string, parts []*FilePart) error

Merge merges files into one file.

func Mkdir

func Mkdir(path string, perm ...iofs.FileMode) error

Mkdir creates a directory.

func Mkdirp

func Mkdirp(path string, perm ...iofs.FileMode) error

Mkdirp creates a deep directory.

func Move

func Move(srcPath, dstPath string) error

Move moves a file or directory

func MoveDir

func MoveDir(srcPath string, dstPath string) error

MoveDir moves a directory.

func MoveFile

func MoveFile(srcPath, dstPath string) error

MoveFile moves a file.

func Open

func Open(path string) (*os.File, error)

Open opens a file, if file not found, creates it.

func OpenFile

func OpenFile(path string, flagAndPerm ...interface{}) (*os.File, error)

OpenFile opens a file.

func ReadFile

func ReadFile(srcPath string) ([]byte, error)

ReadFile reads a file.

func ReadFileAsString

func ReadFileAsString(srcPath string) (string, error)

ReadFileAsString reads a file as string.

func ReadFileLines

func ReadFileLines(srcPath string) ([]string, error)

ReadFileLines reads a file by line.

func Remove

func Remove(path string) error

Remove removes a file or directory

func RemoveDir

func RemoveDir(path string) error

RemoveDir removes a directory.

func RemoveFile

func RemoveFile(path string) error

RemoveFile removes a file.

func Rename

func Rename(srcPath, dstPath string) error

Rename renames a file or directory

func RenameDir

func RenameDir(srcPath string, dstPath string) error

RenameDir renames a directory.

func RenameFile

func RenameFile(srcPath, dstPath string) error

RenameFile renames a file.

func Size

func Size(path string) int64

Size returns the size of the file.

func Stat

func Stat(path string) (os.FileInfo, error)

Stat returns the FileInfo structure describing file.

func SystemConfigDir added in v1.3.12

func SystemConfigDir() string

SystemConfigDir returns the system config directory, which is /etc

func TmpDirPath

func TmpDirPath() string

TmpDirPath returns the path of the temporary directory.

func TmpFilePath

func TmpFilePath() string

TmpFilePath returns the path of the temporary file.

func UserConfigDir added in v1.3.12

func UserConfigDir() string

UserConfigDir returns the user config directory, which is $HOME/.config

func Walk

func Walk(path string, fn iofs.WalkDirFunc) error

Walk walks the files in a directory.

func WalkDir

func WalkDir(path string, fn iofs.WalkDirFunc) error

WalkDir walks the files in a directory.

func WatchDir added in v1.3.0

func WatchDir(ctx context.Context, paths []string, callback func(err error, event string, filepath string)) error

WatchDir watches the changes of files.

func WriteFile

func WriteFile(path string, data []byte) (err error)

WriteFile writes a file.

Types

type FilePart

type FilePart struct {
	Path string
	//
	Index int
}

FilePart represents a part of a file.

Directories

Path Synopsis
type
ini

Jump to

Keyboard shortcuts

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