modulepackage
1.12.1
Repository: https://github.com/arduino/go-paths-helper.git
Documentation: pkg.go.dev
# README
paths: a golang library to simplify handling of paths
This library aims to simplify handling of the most common operations with paths.
For example code that looked like this:
buildPath := getPathFromSomewhere() // returns string
if buildPath != "" {
cachePath, err := filepath.Abs(filepath.Join(buildPath, "cache"))
...
}
can be transformed to:
buildPath := getPathFromSomewhere() // returns *paths.Path
if buildPath != nil {
cachePath, err := buildPath.Join("cache").Abs()
...
}
most operations that usually requires a bit of convoluted system calls are now simplified, for example to check if a path is a directory:
buildPath := "/path/to/somewhere"
srcPath := filepath.Join(buildPath, "src")
if info, err := os.Stat(srcPath); err == nil && !info.IsDir() {
os.MkdirAll(srcPath)
}
using this library can be done this way:
buildPath := paths.New("/path/to/somewhere")
srcPath := buildPath.Join("src")
if !srcPath.IsDir() {
scrPath.MkdirAll()
}
Security
If you think you found a vulnerability or other security-related bug in this project, please read our security policy and report the bug to our Security Team 🛡️ Thank you!
e-mail contact: [email protected]
# Functions
AndFilter creates a ReadDirFilter that accepts all items that are accepted by all the given filters.
FilterDirectories is a ReadDirFilter that accepts only directories.
FilterNames is a ReadDirFilter that accepts only the given filenames.
FilterOutDirectories is a ReadDirFilter that rejects all directories.
FilterOutNames is a ReadDirFilter that rejects the given filenames.
FilterOutPrefixes creates a ReadDirFilter that rejects all the given filename prefixes.
FilterOutSuffixes creates a ReadDirFilter that rejects all the given filename suffixes.
FilterPrefixes creates a ReadDirFilter that accepts only the given filename prefixes.
FilterSuffixes creates a ReadDirFilter that accepts only the given filename suffixes.
Getwd returns a rooted path name corresponding to the current directory.
GUnzip decompress src with gzip and writes the uncompressed file on dst.
MkTempDir creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory.
MkTempFile creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, and returns the resulting *os.File.
New creates a new Path object.
NewFromFile creates a new Path object using the path name obtained from the File object (see os.File.Name function).
NewPathList creates a new PathList with the given paths.
NewProcess creates a command with the provided command line arguments and environment variables (that will be added to the parent os.Environ).
NewProcessFromPath creates a command from the provided executable path, additional environment vars (in addition to the system default ones) and command line arguments.
NotFilter creates a ReadDifFilter that accepts all items rejected by x and viceversa.
NullPath return the path to the /dev/null equivalent for the current OS.
OrFilter creates a ReadDirFilter that accepts all items that are accepted by any (at least one) of the given filters.
TempDir returns the default path to use for temporary files.
WriteToTempFile writes data to a newly generated temporary file.
# Type aliases
PathList is a list of Path.
ReadDirFilter is a filter for Path.ReadDir and Path.ReadDirRecursive methods.