Documentation
¶
Index ¶
- func CopyDir(src string, dst string) (r result.VoidResult)
- func CopyFile(src, dst string) result.VoidResult
- func FileExist(name string) (existed bool, isDir bool)
- func FileExists(name string) bool
- func FilepathAbsolute(paths []string) (r result.Result[[]string])
- func FilepathAbsoluteMap(paths []string) (r result.Result[map[string]string])
- func FilepathContains(basepath string, subpaths []string) (r result.VoidResult)
- func FilepathDistinct(paths []string, toAbs bool) (r result.Result[[]string])
- func FilepathRelative(basepath string, targpaths []string) (r result.Result[[]string])
- func FilepathRelativeMap(basepath string, targpaths []string) (r result.Result[map[string]string])
- func FilepathSame(path1, path2 string) (r result.Result[bool])
- func FilepathSlashInsensitive(path string) string
- func FilepathSplitExt(filename string, slashInsensitive ...bool) (root, ext string)
- func FilepathStem(filename string, slashInsensitive ...bool) string
- func GrepFile(pattern string, filename string) result.Result[[]string]
- func MkdirAll(path string, perm ...os.FileMode) result.VoidResult
- func ReplaceFile(filename string, start, end int, newContent string) result.VoidResult
- func RewriteFile(filename string, fn func(content []byte) result.Result[[]byte]) result.VoidResult
- func RewriteToFile(filename, newFilename string, fn func(content []byte) result.Result[[]byte]) result.VoidResult
- func SearchFile(filename string, paths ...string) result.Result[string]
- func TarGz(src, dst string, includePrefix bool, logOutput func(string, ...interface{}), ...) result.VoidResult
- func TarGzTo(src string, dstWriter io.Writer, includePrefix bool, ...) result.VoidResult
- func WriteFile(filename string, data []byte, perm ...os.FileMode) result.VoidResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDir ¶
func CopyDir(src string, dst string) (r result.VoidResult)
CopyDir copies a whole directory recursively and returns a VoidResult.
func CopyFile ¶
func CopyFile(src, dst string) result.VoidResult
CopyFile copies a single file from src to dst and returns a VoidResult.
func FileExist ¶
FileExist reports whether the named file or directory exists. It returns two values: whether the file exists, and whether it's a directory.
func FileExists ¶
FileExists reports whether the named file or directory exists. It returns true if the file exists, false otherwise.
func FilepathAbsolute ¶
FilepathAbsolute converts all paths to absolute paths and returns a Result.
func FilepathAbsoluteMap ¶
FilepathAbsoluteMap converts all paths to absolute paths and returns a Result.
func FilepathContains ¶
func FilepathContains(basepath string, subpaths []string) (r result.VoidResult)
FilepathContains checks if the basepath contains all the subpaths and returns a VoidResult.
func FilepathDistinct ¶
FilepathDistinct removes duplicate paths and returns a Result. If toAbs is true, returns absolute paths; otherwise returns original paths.
func FilepathRelative ¶
FilepathRelative converts all target paths to relative paths from the base path and returns a Result.
func FilepathRelativeMap ¶
FilepathRelativeMap converts all target paths to relative paths from the base path and returns a Result.
func FilepathSame ¶
FilepathSame checks if the two paths refer to the same file or directory and returns a Result.
func FilepathSlashInsensitive ¶
FilepathSlashInsensitive ignores the difference between the slash and the backslash, and converts to the same as the current system.
func FilepathSplitExt ¶
FilepathSplitExt splits the filename into a pair (root, ext) such that root + ext == filename, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ("", '.cshrc'). If slashInsensitive is true, it ignores the difference between slash and backslash.
func FilepathStem ¶
FilepathStem returns the stem of filename. Example:
FilepathStem("/root/dir/sub/file.ext") // output "file"
If slashInsensitive is true, it ignores the difference between slash and backslash.
func GrepFile ¶
GrepFile searches for lines matching a pattern in a file and returns a Result. Newlines are stripped while reading.
func MkdirAll ¶
func MkdirAll(path string, perm ...os.FileMode) result.VoidResult
MkdirAll creates a directory named path, along with any necessary parents, and returns a VoidResult. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns Ok. If perm is empty, default use 0755.
func ReplaceFile ¶
func ReplaceFile(filename string, start, end int, newContent string) result.VoidResult
ReplaceFile replaces the bytes selected by [start, end] with the new content and returns a VoidResult.
func RewriteFile ¶
RewriteFile rewrites the file content using the provided function and returns a VoidResult.
func RewriteToFile ¶
func RewriteToFile(filename, newFilename string, fn func(content []byte) result.Result[[]byte]) result.VoidResult
RewriteToFile rewrites the file to a new filename using the provided function and returns a VoidResult. If newFilename already exists and is not a directory, replaces it.
func SearchFile ¶
SearchFile searches for a file in the given paths and returns a Result. This is often used to search for config files in /etc, ~/, etc.
func TarGz ¶
func TarGz(src, dst string, includePrefix bool, logOutput func(string, ...interface{}), ignoreElem ...string) result.VoidResult
TarGz compresses and archives files into a tar.gz file and returns a VoidResult. src is the source file or directory to archive. dst is the destination tar.gz file path. includePrefix determines whether to include the parent directory in the archive. logOutput is an optional logging function that will be called for each file processed. ignoreElem is a list of file or directory names to ignore (e.g., ".git", ".DS_Store").
func TarGzTo ¶
func TarGzTo(src string, dstWriter io.Writer, includePrefix bool, logOutput func(string, ...interface{}), ignoreElem ...string) result.VoidResult
TarGzTo compresses and archives files to the given writer and returns a VoidResult. src is the source file or directory to archive. dstWriter is the destination writer. includePrefix determines whether to include the parent directory in the archive. logOutput is an optional logging function that will be called for each file processed. ignoreElem is a list of file or directory names to ignore (e.g., ".git", ".DS_Store").
Types ¶
This section is empty.