Documentation
¶
Index ¶
- Variables
- func Abs(path string) (string, error)
- func AppendFile(path string, data []byte) error
- func BaseName(path string) string
- func Checksum(path string, algorithm string) (string, error)
- func Chmod(name string, mode os.FileMode) error
- func Chown(name string, uid, gid int) error
- func CleanPath(path string) string
- func ConfigDir() string
- func Copy(srcPath, dstPath string) error
- func CopyDir(srcPath string, dstPath string, opts ...CopyDirOption) error
- func CopyFile(srcPath string, dstPath string) error
- func CreateDir(path string, perm ...iofs.FileMode) error
- func CreateFile(path string) (*os.File, error)
- func CreateSymbolicLink(srcPath, dstPath string) error
- func CreateTarGz(destPath string, sources []string) error
- func CurrentDir() string
- func DirName(path string) string
- func DirSize(path string) (int64, error)
- func EnsureDir(path string) error
- func ExtName(path string) string
- func ExtractTarGz(stream io.Reader, destDir string, logHandler func(filename string)) error
- func ExtractZip(zipPath, destDir string) error
- func Glob(pattern string) ([]string, error)
- func GlobDir(dir string, pattern string) ([]string, error)
- func HomeDir() string
- func IsAbsPath(path string) bool
- func IsDir(path string) bool
- func IsEmpty(path string) bool
- func IsExecutable(path string) bool
- func IsExist(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsSymbolicLink(path string) bool
- func IsWritable(path string) bool
- func JoinConfigDir(appName string, configName ...string) string
- func JoinCurrentDir(relativePath string) string
- func JoinHomeDir(relativePath string) string
- func JoinPath(paths ...string) string
- func ListDir(path string) ([]iofs.FileInfo, error)
- func ListDirNames(path string) ([]string, error)
- func Merge(filePath string, parts []*FilePart) error
- func Mkdir(path string, perm ...iofs.FileMode) error
- func Mkdirp(path string, perm ...iofs.FileMode) 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, flagAndPerm ...interface{}) (*os.File, error)
- func ReadFile(srcPath string) ([]byte, error)
- func ReadFileAsString(srcPath string) (string, error)
- func ReadFileLines(srcPath string) ([]string, error)
- func ReadFileRange(path string, offset, length int64) ([]byte, error)
- func ReadSymlink(path string) (string, error)
- func Rel(base, target 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 SafeWriteFile(path string, data []byte) error
- func Size(path string) int64
- func Stat(path string) (os.FileInfo, error)
- func SystemConfigDir() string
- func TmpDirPath() string
- func TmpFilePath() string
- func Touch(path string) error
- func UserConfigDir() string
- func Walk(path string, fn iofs.WalkDirFunc) error
- func WalkDir(path string, fn iofs.WalkDirFunc) error
- func WatchDir(ctx context.Context, paths []string, ...) error
- func WriteFile(path string, data []byte) (err error)
- type CopyDirOption
- type FilePart
Constants ¶
This section is empty.
Variables ¶
var Version = "1.4.1"
Version is the current version of the package.
Functions ¶
func AppendFile ¶ added in v1.3.5
AppendFile appends a file.
func Checksum ¶ added in v1.4.1
Checksum computes a hash of the file and returns its hex-encoded string. Algorithm is case-insensitive: "sha256", "md5" are supported.
func CleanPath ¶ added in v1.4.1
CleanPath returns the shortest path name equivalent to path by purely lexical processing.
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 CopyDir ¶
func CopyDir(srcPath string, dstPath string, opts ...CopyDirOption) error
CopyDir copies a directory. Optional CopyDirOption can exclude paths by pattern (e.g. ".git", "node_modules").
func CreateSymbolicLink ¶
CreateSymbolicLink creates a symbolic link
func CreateTarGz ¶ added in v1.4.1
CreateTarGz creates a gzipped tar archive at destPath from the given sources (files and directories).
func DirSize ¶ added in v1.4.1
DirSize returns the total size in bytes of all regular files under dir (recursive). Symbolic links are not followed.
func EnsureDir ¶ added in v1.4.1
EnsureDir ensures the directory for path exists. If path looks like a file (has a non-empty base name that is not "." or ".."), it ensures the parent directory exists. If path is a directory path, it ensures that directory exists. Typically used before writing a file: EnsureDir(filePath).
func ExtractTarGz ¶ added in v1.2.5
ExtractTarGz extracts a tar.gz file.
func ExtractZip ¶ added in v1.4.1
ExtractZip extracts a zip file at zipPath into destDir.
func Glob ¶ added in v1.4.1
Glob returns the names of all files matching pattern (see filepath.Glob).
func GlobDir ¶ added in v1.4.1
GlobDir returns paths under dir that match pattern (pattern is relative to dir). Returned paths are joined with dir (absolute if dir is absolute).
func IsExecutable ¶ added in v1.4.1
IsExecutable checks whether the path has any execute bit set (user, group, or other). It uses the mode from Stat; useful for scripts and binaries.
func IsReadable ¶ added in v1.4.1
IsReadable checks whether the current user can read the path (file or directory). It attempts to open the path for reading; success means readable.
func IsSymbolicLink ¶
IsSymbolicLink checks whether the path is a symbolic link.
func IsWritable ¶ added in v1.4.1
IsWritable checks whether the current user can write to the path. For a file it tries to open for append; for a directory it tries to create and remove a temp file. Behavior is best-effort and may vary by platform.
func JoinConfigDir ¶ added in v1.3.2
JoinConfigDir returns the config of appName + configName. configName default is config.yml.
func JoinCurrentDir ¶ added in v1.3.2
JoinCurrentDir returns the path which relative with current dir.
func JoinHomeDir ¶ added in v1.3.2
JoinHomeDir returns the path which relative with homedir.
func ListDirNames ¶ added in v1.4.1
ListDirNames returns the names of the entries in the directory (not full paths).
func ReadFileAsString ¶
ReadFileAsString reads a file as string.
func ReadFileLines ¶
ReadFileLines reads a file by line.
func ReadFileRange ¶ added in v1.4.1
ReadFileRange reads up to length bytes from path starting at offset. If length <= 0, reads from offset to end of file.
func ReadSymlink ¶ added in v1.4.1
ReadSymlink returns the destination of the named symbolic link.
func Rel ¶ added in v1.4.1
Rel returns a relative path that is lexically equivalent to target when joined to base.
func SafeWriteFile ¶ added in v1.4.1
SafeWriteFile writes data to path atomically: write to a temp file in the same directory then rename.
func SystemConfigDir ¶ added in v1.3.12
func SystemConfigDir() string
SystemConfigDir returns the system config directory, which is /etc
func Touch ¶ added in v1.4.1
Touch creates an empty file if path does not exist; otherwise updates its modification time to now.
func UserConfigDir ¶ added in v1.3.12
func UserConfigDir() string
UserConfigDir returns the user config directory, which is $HOME/.config
func WalkDir ¶
func WalkDir(path string, fn iofs.WalkDirFunc) error
WalkDir walks the files in a directory.
Types ¶
type CopyDirOption ¶ added in v1.4.1
type CopyDirOption struct {
// Exclude is a list of filepath.Match patterns; paths with any segment matching are skipped.
// Matching directories are skipped entirely (SkipDir).
Exclude []string
}
CopyDirOption configures CopyDir behavior.