Documentation
¶
Index ¶
- Constants
- Variables
- func AbsolutePath(p string) (string, error)
- func AppendFile(p string, data []byte) error
- func AppendFileJson(p string, v any) error
- func AppendFileLines(p string, lines []string) error
- func AppendFileString(p string, data string) error
- func Bunzip2(src, dest string) error
- func Chdir(p string) error
- func Checksum(p string) (string, error)
- func Chmod(p string, mode os.FileMode) error
- func ChmodRecursive(p string, mode os.FileMode) error
- func Chown(p string, uid, gid int) error
- func ChownRecursive(p string, uid, gid int) error
- func CleanPath(p string) string
- func Copy(src, dst string) error
- func CreateDir(p string) error
- func CreateFile(p string) (*os.File, error)
- func CreateTempDir(prefix string) (string, error)
- func CreateTempFile(prefix string) (*os.File, error)
- func Decompress(src, dest string) error
- func Empty(p string) error
- func EmptyDir(p string) error
- func EnsureDir(p string) error
- func EnsureFile(p string) error
- func Exists(p string) bool
- func Flate(src, dest string) error
- func ForceAbsolutePath(p string) string
- func ForceChecksum(p string) string
- func ForceChmodRecursive(p string, mode os.FileMode)
- func ForceChownRecursive(p string, uid, gid int)
- func ForceCreateTempDir(prefix string) string
- func ForceGetCacheDir() string
- func ForceGetConfigDir() string
- func ForceGetCurrentDir() string
- func ForceGetHomeDir() string
- func ForceGetModTime(p string) time.Time
- func ForceGetParentDir(p string) string
- func ForceGetParentDirName(p string) string
- func ForceGlob(dir string, pattern string) []string
- func ForceHash(p string, h hash.Hash) string
- func ForceIsEmpty(p string) bool
- func ForceIsHidden(p string) bool
- func ForceList(p string) []string
- func ForceListDirs(p string) []string
- func ForceListDirsRecursive(p string) []string
- func ForceListFiles(p string) []string
- func ForceListFilesRecursive(p string) []string
- func ForceListRecursive(p string) []string
- func ForceMD5(p string) string
- func ForceMatch(p, pattern string) bool
- func ForceReadFile(p string) []byte
- func ForceReadFileJsonAs[T any](p string) T
- func ForceReadFileLines(p string) []string
- func ForceReadFileString(p string) string
- func ForceReadlink(p string) string
- func ForceRelativePath(base, target string) string
- func ForceSHA1(p string) string
- func ForceSHA256(path string) string
- func ForceSetModeRecursive(p string, mode os.FileMode)
- func ForceSetOwnerRecursive(p string, uid, gid int)
- func ForceSize(p string) int64
- func ForceTouchTempFile(prefix string) string
- func FromBackslashPath(p string) string
- func FromSlashPath(p string) string
- func GetCacheDir() (string, error)
- func GetConfigDir() (string, error)
- func GetCurrentDir() (string, error)
- func GetHomeDir() (string, error)
- func GetInfo(p string) (os.FileInfo, error)
- func GetModTime(p string) (time.Time, error)
- func GetMode(p string) (os.FileMode, error)
- func GetParentDir(p string) (string, error)
- func GetParentDirName(p string) (string, error)
- func GetPathBase(p string) string
- func GetPathExtension(p string) string
- func GetPathExtensionName(p string) string
- func GetPathName(p string) string
- func GetPathParent(p string) string
- func GetPathParentName(p string) string
- func GetPathVolume(p string) string
- func GetPwd() (string, error)
- func GetTempDir() string
- func Glob(dir, pattern string) ([]string, error)
- func Gzip(src, dest string) error
- func HasExtensionPath(p string) bool
- func Hash(p string, h hash.Hash) (string, error)
- func Hide(p string) error
- func IsAbsolutePath(p string) bool
- func IsBackslashPath(p string) bool
- func IsDir(p string) bool
- func IsEmpty(p string) (bool, error)
- func IsExecutable(p string) bool
- func IsFile(p string) bool
- func IsHidden(p string) (bool, error)
- func IsPatternValid(pattern string) bool
- func IsReadable(p string) bool
- func IsSame(p1, p2 string) bool
- func IsSlashPath(p string) bool
- func IsWritable(p string) bool
- func JoinPath(elem ...string) string
- func JoinPathLinux(elem ...string) string
- func JoinPathWindows(elem ...string) string
- func JoinPathWith(sep string, elem ...string) string
- func Link(src, dst string) error
- func List(p string) ([]string, error)
- func ListDirs(p string) ([]string, error)
- func ListDirsRecursive(p string) ([]string, error)
- func ListFiles(p string) ([]string, error)
- func ListFilesRecursive(p string) ([]string, error)
- func ListRecursive(p string) ([]string, error)
- func Lzw(src, dest string) error
- func LzwWith(src, dest string, order lzw.Order, litWidth int) error
- func MD5(p string) (string, error)
- func Match(p, pattern string) (bool, error)
- func Move(src, dst string) error
- func OpenFile(p string) (*os.File, error)
- func OpenZip(path string) (*zip.ReadCloser, error)
- func Pwd() (string, error)
- func ReadFile(p string) ([]byte, error)
- func ReadFileJson(p string, v any) error
- func ReadFileJsonAs[T any](p string) (T, error)
- func ReadFileLines(p string) ([]string, error)
- func ReadFileString(p string) (string, error)
- func Readlink(p string) (string, error)
- func RelativePath(base, target string) (string, error)
- func Remove(p string) error
- func Rename(oldPath, newPath string) error
- func ReplaceInFile(p string, old []byte, new []byte) error
- func ReplaceInFileString(p string, old string, new string) error
- func SHA1(p string) (string, error)
- func SHA256(path string) (string, error)
- func SetHidden(p string, hidden bool) error
- func SetMode(p string, mode os.FileMode) error
- func SetModeRecursive(p string, mode os.FileMode) error
- func SetOwner(p string, uid, gid int) error
- func SetOwnerRecursive(p string, uid, gid int) error
- func Size(p string) (int64, error)
- func SplitPath(p string) []string
- func Symlink(oldname, newname string) error
- func Tar(src, dest string) error
- func TarGz(src, dest string) error
- func ToBackslashPath(p string) string
- func ToSlashPath(p string) string
- func TouchFile(p string) error
- func TouchTempFile(prefix string) (string, error)
- func TruncateFile(p string, size int64) error
- func Unflate(src, dest string) error
- func Ungzip(src, dest string) error
- func Unhide(p string) error
- func Unlzw(src, dest string) error
- func UnlzwWith(src, dest string, order lzw.Order, litWidth int) error
- func Untar(src, dest string) error
- func UntarGz(src, dest string) error
- func Unzip(src, dest string) error
- func Unzlib(src, dest string) error
- func Walk(p string, fn func(string) error) error
- func Watch(ctx context.Context, p string, callback func(event Event)) error
- func WatchGlob(ctx context.Context, dir string, pattern string, callback func(event Event)) error
- func WatchRecursive(ctx context.Context, p string, callback func(event Event)) error
- func WriteFile(p string, data []byte) error
- func WriteFileAtomic(p string, data []byte) error
- func WriteFileJson(p string, v any) error
- func WriteFileJsonAtomic(p string, v any) error
- func WriteFileLines(p string, lines []string) error
- func WriteFileLinesAtomic(p string, lines []string) error
- func WriteFileString(p string, data string) error
- func WriteFileStringAtomic(p string, data string) error
- func Zip(src, dest string) error
- func Zlib(src, dest string) error
- type Bzip2Reader
- type Event
- type FlateReader
- type FlateWriter
- type GzipReader
- type GzipWriter
- type LzwReader
- type LzwWriter
- type PathParts
- type TarGzReader
- type TarGzWriter
- type TarReader
- type TarWriter
- type Watcher
- type ZipWriter
- type ZlibReader
- type ZlibWriter
Constants ¶
const ( DefaultLzwOrder = lzw.MSB DefaultLzwLitWidth = 8 )
DefaultLzwOrder and DefaultLzwLitWidth are the bit ordering and literal code width used by Lzw, Unlzw, OpenLzw and CreateLzw.
Variables ¶
var ( ErrIsDir = errors.New("is a directory") ErrNotDir = errors.New("not a directory") ErrIsFile = errors.New("is a file") ErrNotFile = errors.New("not a file") ErrInvalid = os.ErrInvalid ErrPermission = os.ErrPermission ErrExist = os.ErrExist ErrNotExist = os.ErrNotExist ErrClosed = os.ErrClosed ErrNoDeadline = os.ErrNoDeadline ErrDeadlineExceeded = os.ErrDeadlineExceeded )
var ( EvtCreate = fsnotify.Create EvtRemove = fsnotify.Remove EvtWrite = fsnotify.Write EvtRename = fsnotify.Rename EvtChmod = fsnotify.Chmod EvtError = fsnotify.Op(2048) )
var ErrUnknownFormat = errors.New("unknown archive or compression format")
ErrUnknownFormat is returned by Decompress when the source file does not match any of the supported archive or compression formats.
var (
PathSeparator = string(os.PathSeparator)
)
Functions ¶
func AbsolutePath ¶
AbsolutePath converts a path to an absolute path.
func AppendFile ¶
AppendFile appends the given byte slice data to a file at the specified path. If the file does not exist, it will be created.
func AppendFileJson ¶
AppendFileJson appends the JSON representation of the given variable v to a file at the specified path. If the file does not exist, it will be created. Json will be appended without indentation or newlines. If the file exists, a newline will be added before appending the new JSON.
func AppendFileLines ¶
AppendFileLines appends the given slice of strings to a file at the specified p, with each string representing a line in the file. If the file does not exist, it will be created. If the file exists, a newline will be added before appending the new lines.
func AppendFileString ¶
AppendFileString appends the given string data to a file at the specified path. If the file does not exist, it will be created.
func Bunzip2 ¶ added in v0.1.0
Bunzip2 decompresses the bzip2-compressed source file into the destination file.
func Chdir ¶
Chdir changes the current working directory to the specified path. If the path does not exist or is not a directory, it returns an error.
func ChmodRecursive ¶ added in v0.1.0
ChmodRecursive recursively changes permissions for a directory and all its contents.
func Chown ¶
Chown changes the ownership of a file at the specified path to the given user ID (uid) and group ID (gid). If the path does not exist, it returns an error.
func ChownRecursive ¶ added in v0.1.0
ChownRecursive recursively changes ownership for a directory and all its contents.
func CleanPath ¶
CleanPath returns the shortest path equivalent to p by eliminating . and .. elements.
func Copy ¶
Copy copies a file or directory from src to dst. If src is a directory, it copies the entire directory recursively. If src is a file, it copies the file. If dst does not exist, it will be created. If it exists, it will be merged (for directories) or overwritten (for files).
func CreateDir ¶
CreateDir creates a directory at the specified path, including any necessary parent directories. If the directory already exists, it does nothing and returns nil.
func CreateFile ¶ added in v0.1.0
CreateFile creates a new file at the specified path. Alias for os.Create.
func CreateTempDir ¶
CreateTempDir creates a temporary directory with the specified prefix in the system's default temporary directory. It returns the full path of the created directory.
func CreateTempFile ¶
CreateTempFile creates a temporary file with the specified prefix in the system's default temporary directory and returns an open file handle to it.
func Decompress ¶ added in v0.1.0
Decompress inspects the source file's contents and extracts or decompresses it into dest using whichever of Unzip, Untar, UntarGz, Ungzip, Unzlib or Bunzip2 matches. If the format cannot be identified, it returns ErrUnknownFormat.
dest is a directory for archive formats (zip, tar, tar.gz) and a file for single-stream formats (gzip, zlib, bzip2), matching the corresponding UnX function.
Raw DEFLATE (Flate) and LZW streams carry no header identifying them and cannot be auto-detected; call Unflate or Unlzw directly for those.
func EmptyDir ¶
EmptyDir removes all contents of the directory at the specified path without deleting the directory itself. If the directory does not exist, it returns an error. If the path points to a file, it returns an error.
func EnsureDir ¶
EnsureDir ensures that a directory exists at the specified path. It follows these rules:
- If the p points to an existing file, it returns an error.
- If the directory already exists, it does nothing and returns nil.
- If the directory does not exist, it creates the directory along with any necessary parent directories.
func EnsureFile ¶
EnsureFile ensures that a file exists at the specified path. It follows these rules:
- If the p points to an existing directory, it returns an error.
- If the file already exists, it does nothing and returns nil.
- If the file does not exist, it creates any necessary parent directories and then creates an empty file at the specified path.
func Flate ¶ added in v0.1.0
Flate compresses the source file into a raw DEFLATE-compressed file at the destination path. src must be a file; if it is a directory, it returns ErrIsDir.
func ForceAbsolutePath ¶
ForceAbsolutePath is like AbsolutePath but ignores errors and returns an empty string on error.
func ForceChecksum ¶
ForceChecksum is like Checksum but ignores errors and returns an empty string on error.
func ForceChmodRecursive ¶ added in v0.1.0
ForceChmodRecursive is like ChmodRecursive but ignores errors.
func ForceChownRecursive ¶ added in v0.1.0
ForceChownRecursive is like ChownRecursive but ignores errors.
func ForceCreateTempDir ¶
ForceCreateTempDir is like CreateTempDir but ignores errors and returns an empty string on error.
func ForceGetCacheDir ¶
func ForceGetCacheDir() string
ForceGetCacheDir is like GetCacheDir but ignores errors and returns an empty string on error.
func ForceGetConfigDir ¶
func ForceGetConfigDir() string
ForceGetConfigDir is like GetConfigDir but ignores errors and returns an empty string on error.
func ForceGetCurrentDir ¶
func ForceGetCurrentDir() string
ForceGetCurrentDir is like GetCurrentDir but ignores errors and returns an empty string on error.
func ForceGetHomeDir ¶
func ForceGetHomeDir() string
ForceGetHomeDir is like GetHomeDir but ignores errors and returns an empty string on error.
func ForceGetModTime ¶
ForceGetModTime is like GetModTime but ignores errors and returns zero time on error.
func ForceGetParentDir ¶
ForceGetParentDir is like GetParentDir but ignores errors and returns an empty string on error.
func ForceGetParentDirName ¶
ForceGetParentDirName is like GetParentDirName but ignores errors and returns an empty string on error.
func ForceIsEmpty ¶
ForceIsEmpty is like IsEmpty but ignores errors and returns false on error.
func ForceIsHidden ¶
ForceIsHidden is like IsHidden but ignores errors and returns false on error.
func ForceListDirs ¶
ForceListDirs is like ListDirs but ignores errors and returns an empty slice on error.
func ForceListDirsRecursive ¶
ForceListDirsRecursive is like ListDirsRecursive but ignores errors and returns an empty slice on error.
func ForceListFiles ¶
ForceListFiles is like ListFiles but ignores errors and returns an empty slice on error.
func ForceListFilesRecursive ¶
ForceListFilesRecursive is like ListFilesRecursive but ignores errors and returns an empty slice on error.
func ForceListRecursive ¶
ForceListRecursive is like ListRecursive but ignores errors and returns an empty slice on error.
func ForceMatch ¶
ForceMatch is like Match but ignores errors and returns false on error.
func ForceReadFile ¶
ForceReadFile is like ReadFile but ignores errors and returns an empty slice on error.
func ForceReadFileJsonAs ¶ added in v0.1.0
ForceReadFileJsonAs is like ReadFileJsonAs but ignores errors and returns the zero value of type T on error.
func ForceReadFileLines ¶
ForceReadFileLines is like ReadFileLines but ignores errors and returns an empty slice on error.
func ForceReadFileString ¶
ForceReadFileString is like ReadFileString but ignores errors and returns an empty string on error.
func ForceReadlink ¶
ForceReadlink is like Readlink but ignores errors and returns an empty string on error.
func ForceRelativePath ¶
ForceRelativePath is like RelativePath but ignores errors and returns the target path on error.
func ForceSHA256 ¶
ForceSHA256 is like SHA256 but ignores errors and returns an empty string on error.
func ForceSetModeRecursive ¶ added in v0.1.0
ForceSetModeRecursive is like SetModeRecursive but ignores errors.
func ForceSetOwnerRecursive ¶ added in v0.1.0
ForceSetOwnerRecursive is like SetOwnerRecursive but ignores errors.
func ForceTouchTempFile ¶ added in v0.1.0
ForceTouchTempFile is like TouchTempFile but ignores errors and returns an empty string on error.
func FromBackslashPath ¶
FromBackslashPath converts backslashes to forward slashes.
func FromSlashPath ¶
FromSlashPath converts forward slashes to the OS-specific separator.
func GetCacheDir ¶
GetCacheDir returns the cache directory of the current user.
func GetConfigDir ¶
GetConfigDir returns the configuration directory of the current user.
func GetHomeDir ¶
GetHomeDir returns the home directory of the current user.
func GetInfo ¶
GetInfo returns a FileInfo describing the file at the specified path. If the path does not exist, it returns an error.
func GetModTime ¶
GetModTime returns the modification time of a file at the specified path as a Unix timestamp (seconds since January 1, 1970). If the path does not exist or is a directory, it returns an error.
func GetMode ¶
GetMode returns the file mode (permissions) of a file at the specified path. If the path does not exist, it returns an error.
func GetParentDir ¶
GetParentDir returns the parent directory of a file or directory path.
func GetParentDirName ¶
GetParentDirName returns the name of the parent directory of a file or directory path.
func GetPathBase ¶
GetPathBase returns the last element of the path, which is typically the file name or the last directory in the path.
/home/users/dev/fs/path.go -> path.go /home/users/dev/fs/ -> fs /home/users/dev/fs -> fs
func GetPathExtension ¶
GetPathExtension returns the file extension, including the dot.
/home/users/dev/fs/path.go -> .go /home/users/dev/fs/ -> "" /home/users/dev/fs -> ""
func GetPathExtensionName ¶
GetPathExtensionName returns the file extension without the dot.
/home/users/dev/fs/path.go -> go /home/users/dev/fs/ -> "" /home/users/dev/fs -> ""
func GetPathName ¶
GetPathName returns the file name without the extension.
/home/users/dev/fs/path.go -> path /home/users/dev/fs/ -> fs /home/users/dev/fs -> fs
func GetPathParent ¶
GetPathParent returns the parent directory of the given path.
/home/users/dev/fs/path.go -> /home/users/dev/fs /home/users/dev/fs/ -> /home/users/dev /home/users/dev/fs -> /home/users/dev
func GetPathParentName ¶
GetPathParentName returns the name of the parent directory of the given path.
/home/users/dev/fs/path.go -> fs /home/users/dev/fs/ -> dev /home/users/dev/fs -> dev
func GetPathVolume ¶
GetPathVolume returns the volume name of the given path. On Windows, this is the drive letter (e.g., "C:"). On Unix-like systems, this will be an empty string.
C:\Users\dev\fs\path.go -> C:
func GetTempDir ¶
func GetTempDir() string
GetTempDir returns the default temporary directory of the system.
func Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in filepath.Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
func Gzip ¶ added in v0.1.0
Gzip compresses the source file into a gzip-compressed file at the destination path. src must be a file; if it is a directory, it returns ErrIsDir.
func HasExtensionPath ¶
HasExtensionPath checks if a path has a file extension.
func IsAbsolutePath ¶
IsAbsolutePath checks if a path is absolute.
func IsBackslashPath ¶
IsBackslashPath checks if a path contains backslashes.
func IsDir ¶
IsDir checks if the given p is a directory. If the p does not exist or is a file, it returns false.
func IsEmpty ¶
IsEmpty checks if a file or directory at the specified path is empty. For files, it checks if the file size is zero bytes. For directories, it checks if the directory contains no files or subdirectories. If the path does not exist, it returns an error but also true.
func IsExecutable ¶
IsExecutable checks if a file at the specified path is executable.
func IsFile ¶
IsFile checks if the given p is a file. If the p does not exist or is a directory, it returns false.
func IsHidden ¶
IsHidden checks if a file or directory is hidden (starts with a dot on Unix-like systems).
func IsPatternValid ¶
IsPatternValid checks if the given glob pattern is valid.
func IsReadable ¶
IsReadable checks if a file at the specified path is readable.
func IsSame ¶
IsSame checks if two paths refer to the same file by comparing their inode information.
func IsSlashPath ¶
IsSlashPath checks if a path contains forward slashes.
func IsWritable ¶
IsWritable checks if a file at the specified path is writable.
func JoinPathLinux ¶
JoinPathLinux joins path elements using forward slashes (Unix-style).
func JoinPathWindows ¶
JoinPathWindows joins path elements using backslashes (Windows-style).
func JoinPathWith ¶
JoinPathWith joins path elements using a specific separator.
func Link ¶
Link creates a hard link from src to dst. If src does not exist or dst already exists, it returns an error.
func List ¶
List returns a slice of names of all entries (files and directories) within the specified directory path. If the directory does not exist or is not accessible, it returns an error. This function does not include the full paths, only the names of the entries.
This function is not recursive; it only lists entries in the specified directory, not in its subdirectories.
func ListDirs ¶
ListDirs returns a slice of names of all directories within the specified directory path. If the directory does not exist or is not accessible, it returns an error. This function does not include the full paths, only the names of the entries.
This function is not recursive; it only lists entries in the specified directory, not in its subdirectories.
func ListDirsRecursive ¶
ListDirsRecursive returns a slice of relative paths of all directories within the specified directory path and its subdirectories. If the directory does not exist or is not accessible, it returns an error. The returned paths are relative to the specified directory.
This function is recursive; it lists directories in the specified directory and all its subdirectories.
func ListFiles ¶
ListFiles returns a slice of names of all files within the specified directory path. If the directory does not exist or is not accessible, it returns an error. This function does not include the full paths, only the names of the entries.
This function is not recursive; it only lists entries in the specified directory, not in its subdirectories.
func ListFilesRecursive ¶
ListFilesRecursive returns a slice of relative paths of all files within the specified directory path and its subdirectories. If the directory does not exist or is not accessible, it returns an error. The returned paths are relative to the specified directory.
This function is recursive; it lists files in the specified directory and all its subdirectories.
func ListRecursive ¶
ListRecursive returns a slice of relative paths of all entries (files and directories) within the specified directory path and its subdirectories. If the directory does not exist or is not accessible, it returns an error. The returned paths are relative to the specified directory.
This function is recursive; it lists entries in the specified directory and all its subdirectories.
func Lzw ¶ added in v0.1.0
Lzw compresses the source file into an LZW-compressed file at the destination path, using DefaultLzwOrder and DefaultLzwLitWidth. src must be a file; if it is a directory, it returns ErrIsDir.
func LzwWith ¶ added in v0.1.0
LzwWith is like Lzw but allows the bit ordering and literal code width to be specified explicitly. litWidth must be in the range [2,8] and must match the litWidth used to decompress the file.
func Move ¶
Move moves a file or directory from src to dst. It is equivalent to renaming the file or directory. If src and dst are on different filesystems, it performs a copy followed by a delete of the original.
func OpenFile ¶
OpenFile opens the file at the specified path for reading. It returns a file handle and an error. If the file does not exist or is not accessible, it returns an error.
func OpenZip ¶ added in v0.1.0
func OpenZip(path string) (*zip.ReadCloser, error)
OpenZip opens the zip archive at the specified path for reading.
func ReadFileJson ¶
ReadFileJson reads a JSON file and unmarshals its content into the provided variable v, which should be a pointer to the desired data structure.
func ReadFileJsonAs ¶ added in v0.1.0
ReadFileJsonAs reads a JSON file and unmarshals it into a value of type T, returning the result with type safety.
func ReadFileLines ¶
ReadFileLines reads a file and returns its content as a slice of strings, where each string represents a line in the file.
func ReadFileString ¶
ReadFileString reads the entire content of a file and returns it as a string.
func RelativePath ¶
RelativePath returns the relative path from base to target.
func Remove ¶
Remove removes a file or directory at the specified path. If the path is a directory, it removes the directory and all its contents recursively. If the path does not exist, it returns nil (no error). If there is an error, it will be of type [*PathError].
func Rename ¶
Rename renames (moves) a file or directory from oldPath to newPath. If oldPath and newPath are on different filesystems, it performs a copy followed by a delete of the original.
func ReplaceInFile ¶
ReplaceInFile reads the content of the file at the specified path, replaces all occurrences of the old byte slice with the new byte slice, and writes the modified content back to the file. If the old byte slice is not found in the file, it does nothing.
func ReplaceInFileString ¶
ReplaceInFileString is like ReplaceInFile but works with strings instead of byte slices.
func SetHidden ¶
SetHidden sets the hidden status of a file or directory by renaming it to/from a dot-prefixed name.
func SetMode ¶
SetMode sets the file mode (permissions) of a file at the specified path. If the path does not exist, it returns an error.
func SetModeRecursive ¶ added in v0.1.0
SetModeRecursive recursively sets the file mode (permissions) for a directory and all its contents.
func SetOwnerRecursive ¶ added in v0.1.0
SetOwnerRecursive recursively changes ownership for a directory and all its contents.
func Size ¶
Size returns the size of a file or directory at the specified path in bytes. If the path is a directory, it computes the total size of all files within the directory recursively. It returns the size in bytes.
func Symlink ¶
Symlink creates a symbolic link from oldname to newname. If oldname does not exist or newname already exists, it returns an error.
func Tar ¶ added in v0.1.0
Tar archives the source file or directory into a tar archive at the destination path. If src is a directory, its contents are added to the archive using paths relative to src; the directory itself is not nested inside the archive.
func TarGz ¶ added in v0.1.0
TarGz archives the source file or directory into a gzip-compressed tar archive at the destination path, combining Tar and Gzip in a single pass. If src is a directory, its contents are added to the archive using paths relative to src; the directory itself is not nested inside the archive.
func ToBackslashPath ¶
ToBackslashPath converts forward slashes to backslashes.
func ToSlashPath ¶
ToSlashPath converts the path to use forward slashes.
func TouchFile ¶
TouchFile creates an empty file at the specified path if it does not already exist.
func TouchTempFile ¶ added in v0.1.0
TouchTempFile creates a temporary file with the specified prefix in the system's default temporary directory. It returns the full path of the created file.
func TruncateFile ¶
TruncateFile truncates the file at the specified path to the given size in bytes. If the path points to a directory or does not exist, it returns an error.
func Unflate ¶ added in v0.1.0
Unflate decompresses the raw DEFLATE-compressed source file into the destination file.
func Ungzip ¶ added in v0.1.0
Ungzip decompresses the gzip-compressed source file into the destination file.
func Unlzw ¶ added in v0.1.0
Unlzw decompresses the LZW-compressed source file into the destination file, using DefaultLzwOrder and DefaultLzwLitWidth.
func UnlzwWith ¶ added in v0.1.0
UnlzwWith is like Unlzw but allows the bit ordering and literal code width to be specified explicitly. They must match the values used to compress the file.
func Untar ¶ added in v0.1.0
Untar extracts the contents of a tar archive at the source path into the destination directory.
func UntarGz ¶ added in v0.1.0
UntarGz extracts the contents of a gzip-compressed tar archive at the source path into the destination directory.
func Unzip ¶ added in v0.1.0
Unzip extracts the contents of a zip archive at the source path into the destination directory.
func Unzlib ¶ added in v0.1.0
Unzlib decompresses the zlib-compressed source file into the destination file.
func Walk ¶
Walk traverses the directory tree rooted at the specified path, calling the provided function for each file or directory encountered. The function receives the full path of the file or directory as its argument. If the function returns an error, the walk is aborted and the error is returned.
func Watch ¶
Watch watches a single path for file system events and calls the callback for each event.
func WatchGlob ¶
WatchGlob watches a directory and filters events by a glob pattern. The pattern is matched against paths relative to the directory.
func WatchRecursive ¶
WatchRecursive watches a directory and all its subdirectories for file system events. It automatically adds and removes subdirectories as they are created and deleted.
func WriteFile ¶
WriteFile writes the given byte slice data to a file at the specified path. IF the directory does not exist, it will fail. If the file exists, it will be overwritten.
func WriteFileAtomic ¶ added in v0.1.0
WriteFileAtomic writes data to a temporary file and atomically renames it to the target path. This ensures that the file is either fully written or not written at all, preventing partial writes.
func WriteFileJson ¶
WriteFileJson marshals the given variable v into JSON format and writes it to a file at the specified path. If the directory does not exist, it will fail. If the file exists, it will be overwritten.
func WriteFileJsonAtomic ¶ added in v0.1.0
WriteFileJsonAtomic is like WriteFileAtomic but marshals a value to JSON first.
func WriteFileLines ¶
WriteFileLines writes the given slice of strings to a file at the specified path, with each string representing a line in the file. If the directory does not exist, it will fail. If the file exists, it will be overwritten.
func WriteFileLinesAtomic ¶ added in v0.1.0
WriteFileLinesAtomic is like WriteFileAtomic but accepts a slice of strings (lines).
func WriteFileString ¶
WriteFileString writes the given string data to a file at the specified path. If the directory does not exist, it will fail. If the file exists, it will be overwritten.
func WriteFileStringAtomic ¶ added in v0.1.0
WriteFileStringAtomic is like WriteFileAtomic but accepts a string.
Types ¶
type Bzip2Reader ¶ added in v0.1.0
Bzip2Reader reads bzip2-compressed data from a file, closing the underlying file on Close.
func OpenBzip2 ¶ added in v0.1.0
func OpenBzip2(path string) (*Bzip2Reader, error)
OpenBzip2 opens the bzip2-compressed file at the specified path for reading.
func (*Bzip2Reader) Close ¶ added in v0.1.0
func (r *Bzip2Reader) Close() error
Close closes the underlying file.
type FlateReader ¶ added in v0.1.0
type FlateReader struct {
io.ReadCloser
// contains filtered or unexported fields
}
FlateReader reads raw DEFLATE-compressed data from a file, closing both the flate stream and the underlying file on Close.
func OpenFlate ¶ added in v0.1.0
func OpenFlate(path string) (*FlateReader, error)
OpenFlate opens the raw DEFLATE-compressed file at the specified path for reading.
func (*FlateReader) Close ¶ added in v0.1.0
func (r *FlateReader) Close() error
Close closes the flate stream and the underlying file.
type FlateWriter ¶ added in v0.1.0
FlateWriter writes raw DEFLATE-compressed data to a file, closing both the flate stream and the underlying file on Close.
func CreateFlate ¶ added in v0.1.0
func CreateFlate(path string) (*FlateWriter, error)
CreateFlate creates a new raw DEFLATE-compressed file at the specified path for writing.
func (*FlateWriter) Close ¶ added in v0.1.0
func (w *FlateWriter) Close() error
Close flushes and closes the flate stream, then closes the underlying file.
type GzipReader ¶ added in v0.1.0
GzipReader reads gzip-compressed data from a file, closing both the gzip stream and the underlying file on Close.
func OpenGzip ¶ added in v0.1.0
func OpenGzip(path string) (*GzipReader, error)
OpenGzip opens the gzip-compressed file at the specified path for reading.
func (*GzipReader) Close ¶ added in v0.1.0
func (r *GzipReader) Close() error
Close closes the gzip stream and the underlying file.
type GzipWriter ¶ added in v0.1.0
GzipWriter writes gzip-compressed data to a file, closing both the gzip stream and the underlying file on Close.
func CreateGzip ¶ added in v0.1.0
func CreateGzip(path string) (*GzipWriter, error)
CreateGzip creates a new gzip-compressed file at the specified path for writing.
func (*GzipWriter) Close ¶ added in v0.1.0
func (w *GzipWriter) Close() error
Close flushes and closes the gzip stream, then closes the underlying file.
type LzwReader ¶ added in v0.1.0
type LzwReader struct {
io.ReadCloser
// contains filtered or unexported fields
}
LzwReader reads LZW-compressed data from a file, closing both the LZW stream and the underlying file on Close.
func OpenLzw ¶ added in v0.1.0
OpenLzw opens the LZW-compressed file at the specified path for reading, using DefaultLzwOrder and DefaultLzwLitWidth.
func OpenLzwWith ¶ added in v0.1.0
OpenLzwWith is like OpenLzw but allows the bit ordering and literal code width to be specified explicitly. They must match the values used to compress the file.
type LzwWriter ¶ added in v0.1.0
type LzwWriter struct {
io.WriteCloser
// contains filtered or unexported fields
}
LzwWriter writes LZW-compressed data to a file, closing both the LZW stream and the underlying file on Close.
func CreateLzw ¶ added in v0.1.0
CreateLzw creates a new LZW-compressed file at the specified path for writing, using DefaultLzwOrder and DefaultLzwLitWidth.
func CreateLzwWith ¶ added in v0.1.0
CreateLzwWith is like CreateLzw but allows the bit ordering and literal code width to be specified explicitly. litWidth must be in the range [2,8].
type PathParts ¶
type PathParts struct {
Absolute string // Absolute path (eg: /home/users/dev/fs/path.go)
Base string // Base name (eg: path.go)
Name string // Name without extension (eg: path)
Ext string // Extension with dot (eg: .go)
ExtName string // Extension without dot (eg: go)
Parent string // Parent directory (eg: /home/users/dev/fs)
ParentName string // Parent directory name (eg: fs)
Volume string // Volume name (eg: C: on Windows, empty on Unix)
}
func GetDirParts ¶
GetDirParts returns all path components for a directory as a PathParts struct.
func GetPathParts ¶
GetPathParts returns a PathParts struct containing various components of the given path.
type TarGzReader ¶ added in v0.1.0
TarGzReader reads a gzip-compressed tar archive from a file, closing the tar stream, the gzip stream and the underlying file on Close.
func OpenTarGz ¶ added in v0.1.0
func OpenTarGz(path string) (*TarGzReader, error)
OpenTarGz opens the gzip-compressed tar archive at the specified path for reading.
func (*TarGzReader) Close ¶ added in v0.1.0
func (r *TarGzReader) Close() error
Close closes the gzip stream and the underlying file.
type TarGzWriter ¶ added in v0.1.0
TarGzWriter writes a gzip-compressed tar archive to a file, closing the tar stream, the gzip stream and the underlying file on Close.
func CreateTarGz ¶ added in v0.1.0
func CreateTarGz(path string) (*TarGzWriter, error)
CreateTarGz creates a new gzip-compressed tar archive at the specified path for writing.
func (*TarGzWriter) Close ¶ added in v0.1.0
func (w *TarGzWriter) Close() error
Close flushes and closes the tar stream and the gzip stream, then closes the underlying file.
type TarReader ¶ added in v0.1.0
TarReader reads a tar archive from a file, closing both the tar stream and the underlying file on Close.
type TarWriter ¶ added in v0.1.0
TarWriter writes a tar archive to a file, closing both the tar stream and the underlying file on Close.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
type ZipWriter ¶ added in v0.3.0
ZipWriter writes a zip archive to a file, closing both the zip stream and the underlying file on Close.
type ZlibReader ¶ added in v0.1.0
type ZlibReader struct {
io.ReadCloser
// contains filtered or unexported fields
}
ZlibReader reads zlib-compressed data from a file, closing both the zlib stream and the underlying file on Close.
func OpenZlib ¶ added in v0.1.0
func OpenZlib(path string) (*ZlibReader, error)
OpenZlib opens the zlib-compressed file at the specified path for reading.
func (*ZlibReader) Close ¶ added in v0.1.0
func (r *ZlibReader) Close() error
Close closes the zlib stream and the underlying file.
type ZlibWriter ¶ added in v0.1.0
ZlibWriter writes zlib-compressed data to a file, closing both the zlib stream and the underlying file on Close.
func CreateZlib ¶ added in v0.1.0
func CreateZlib(path string) (*ZlibWriter, error)
CreateZlib creates a new zlib-compressed file at the specified path for writing.
func (*ZlibWriter) Close ¶ added in v0.1.0
func (w *ZlibWriter) Close() error
Close flushes and closes the zlib stream, then closes the underlying file.