fsx

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 25 Imported by: 0

README

A simple and intuitive Go library that provides convenient functions for file system operations. It offers a clean API for common tasks like reading files, manipulating paths, and watching for system events.

config, err := fsx.ReadFileJsonAs[Config]("./config.json")
if err != nil {
  panic(err)
}

fsx.WatchRecursive(context.Background(), config.BaseDir, func (e fsx.Event) {
  println(e.Path, "has changed")
})

Getting Started

go get github.com/renatopp/go-x

After installing, you can import the package and use the fsx name:

import "github.com/renatopp/go-x/fsx"

func main() {
  fsx.Watch(context.Background(), "./assets", func (e fsx.Event) {
    checksum := fsx.ForceChecksum(e.Path)
    if fsx.IsDir(e.Path) {
      println("DIR:", checksum)
    } else {
      println("FILE:", checksum)
    }
  })
}

API Overview

All functions are named to reflect how they can be used and their behavior:

Prefix Description Examples
*File Operates on files exclusively, errors on directories ReadFile(), IsFile(), ListFiles()
*Dir Operates on directories exclusively or returns directories EmptyDir(), GetHomeDir(), ListDirs()
*Path Manipulates path strings (not file system) JoinPath(), GetPathName(), CleanPath()
Force* Ignores errors and returns zero values; works with (value, error) functions ForceReadFile(), ForceSize()
*Recursive Operates on directories and all subdirectories ListFilesRecursive(), ChmodRecursive()
*Atomic Writes to temp file then renames for safety WriteFileAtomic(), WriteFileJsonAtomic()
Other Handles files and directories differently as needed Copy(), Remove(), Hide()

Checks

Check file system state without modifying:

Function Description
Exists(p) Checks if a file or directory exists
IsFile(p) Checks if path is a regular file
IsDir(p) Checks if path is a directory
IsEmpty(p) Checks if file is empty (0 bytes) or directory is empty (no entries)
ForceIsEmpty(p) Like IsEmpty, ignores errors
IsSame(p1, p2) Checks if two paths refer to the same file (inode comparison)
IsExecutable(p) Checks if file has execute permission
IsReadable(p) Checks if file is readable
IsWritable(p) Checks if file is writable
IsHidden(p) Checks if file/dir is hidden (starts with .)
ForceIsHidden(p) Like IsHidden, ignores errors
IsPatternValid(pattern) Validates a glob pattern
IsAbsolutePath(p) Checks if path is absolute
IsSlashPath(p) Checks if path contains forward slashes
IsBackslashPath(p) Checks if path contains backslashes
HasExtensionPath(p) Checks if path has a file extension

File Operations

Reading, writing, and modifying files:

Reading Files

Function Description
OpenFile(p) Opens file for reading, returns *os.File
ReadFile(p) Reads entire file as byte slice
ForceReadFile(p) Like ReadFile, ignores errors
ReadFileString(p) Reads entire file as string
ForceReadFileString(p) Like ReadFileString, ignores errors
ReadFileLines(p) Reads file and splits into lines
ForceReadFileLines(p) Like ReadFileLines, ignores errors
ReadFileJson(p, v) Reads JSON file and unmarshals to pointer
ReadFileJsonAs[T](p) Type-safe JSON read with generics
ForceReadFileJsonAs[T](p) Like ReadFileJsonAs, ignores errors

Writing Files

Function Description
CreateFile(p) Creates new file, returns *os.File
WriteFile(p, data) Writes bytes to file (overwrites)
WriteFileString(p, data) Writes string to file
WriteFileLines(p, lines) Writes lines to file (joined by newline)
WriteFileJson(p, v) Marshals value to JSON and writes
WriteFileAtomic(p, data) Writes bytes atomically (temp + rename)
WriteFileStringAtomic(p, data) Writes string atomically
WriteFileLinesAtomic(p, lines) Writes lines atomically
WriteFileJsonAtomic(p, v) Marshals and writes JSON atomically
AppendFile(p, data) Appends bytes to file (creates if missing)
AppendFileString(p, data) Appends string to file
AppendFileLines(p, lines) Appends lines to file
AppendFileJson(p, v) Appends JSON to file (compact, no indent)

File Metadata

Function Description
TouchFile(p) Creates empty file if it doesn't exist
EnsureFile(p) Ensures file exists (creates parent dirs)
TruncateFile(p, size) Truncates file to size bytes
ReplaceInFile(p, old, new) Replaces all occurrences of old with new
ReplaceInFileString(p, old, new) Like ReplaceInFile with strings

Temporary Files

Function Description
TouchTempFile(prefix) Creates temporary file, returns path
ForceTouchTempFile(prefix) Like TouchTempFile, ignores errors
CreateTempFile(prefix) Creates temporary file, returns *os.File

Directory Operations

Creating, managing, and inspecting directories:

Directory Inspection

Function Description
ListDirs(p) Lists directory names in directory
ForceListDirs(p) Like ListDirs, ignores errors
ListDirsRecursive(p) Lists all subdirectories recursively (relative paths)
ForceListDirsRecursive(p) Like ListDirsRecursive, ignores errors
GetCurrentDir() Gets current working directory
ForceGetCurrentDir() Like GetCurrentDir, ignores errors
GetTempDir() Gets system temp directory
GetCacheDir() Gets user cache directory
ForceGetCacheDir() Like GetCacheDir, ignores errors
GetConfigDir() Gets user config directory
ForceGetConfigDir() Like GetConfigDir, ignores errors
GetHomeDir() Gets user home directory
ForceGetHomeDir() Like GetHomeDir, ignores errors
GetParentDir(p) Gets parent directory of path
ForceGetParentDir(p) Like GetParentDir, ignores errors
GetParentDirName(p) Gets name of parent directory
ForceGetParentDirName(p) Like GetParentDirName, ignores errors
GetDirParts(p) Gets all path components for directory as PathParts struct

Directory Creation & Modification

Function Description
CreateDir(p) Creates directory with parent dirs
EnsureDir(p) Ensures directory exists (errors on file)
CreateTempDir(prefix) Creates temporary directory
ForceCreateTempDir(prefix) Like CreateTempDir, ignores errors
EmptyDir(p) Removes all contents of directory
Chdir(p) Changes current working directory

Path Manipulation

String-based path operations (no file system access):

Function Description
JoinPath(elem...) Joins elements using OS separator
JoinPathLinux(elem...) Joins using forward slashes
JoinPathWindows(elem...) Joins using backslashes
JoinPathWith(sep, elem...) Joins using custom separator
AbsolutePath(p) Converts to absolute path
ForceAbsolutePath(p) Like AbsolutePath, ignores errors
RelativePath(base, target) Computes relative path from base to target
ForceRelativePath(base, target) Like RelativePath, ignores errors
CleanPath(p) Returns shortest equivalent path
ToSlashPath(p) Converts to forward slashes
FromSlashPath(p) Converts to OS separator
ToBackslashPath(p) Converts to backslashes
FromBackslashPath(p) Converts backslashes to forward slashes
SplitPath(p) Splits path into components
GetPathBase(p) Gets filename/dirname with extension
GetPathName(p) Gets name without extension
GetPathExtension(p) Gets extension with dot (.go)
GetPathExtensionName(p) Gets extension without dot (go)
GetPathParent(p) Gets parent directory path
GetPathParentName(p) Gets parent directory name
GetPathVolume(p) Gets volume name (Windows: C:, Unix: "")
GetPathParts(p) Gets all components as PathParts struct

File System Traversal

Listing and walking directories:

Function Description
List(p) Lists all entries (files + dirs) in directory
ForceList(p) Like List, ignores errors
ListRecursive(p) Lists all entries recursively (relative paths)
ForceListRecursive(p) Like ListRecursive, ignores errors
ListFiles(p) Lists files only in directory
ForceListFiles(p) Like ListFiles, ignores errors
ListFilesRecursive(p) Lists all files recursively (relative paths)
ForceListFilesRecursive(p) Like ListFilesRecursive, ignores errors
Walk(p, fn) Walks directory tree calling fn for each entry
Glob(dir, pattern) Matches files against glob pattern
ForceGlob(dir, pattern) Like Glob, ignores errors
Match(p, pattern) Checks if path matches glob pattern
ForceMatch(p, pattern) Like Match, ignores errors

Compression & Archiving

Compressing and archiving files and directories, built entirely on the standard library (archive/zip, archive/tar, compress/gzip, compress/zlib, compress/flate, compress/lzw, compress/bzip2).

Zip/Tar/TarGz accept a file or directory as src; a directory's contents are archived using paths relative to src (the directory itself is not nested inside the archive). Gzip/Zlib/Flate/Lzw compress a single file only and return ErrIsDir if src is a directory.

Zip

Function Description
Zip(src, dest) Compresses a file or directory into a zip archive
Unzip(src, dest) Extracts a zip archive into a directory
OpenZip(path) Opens a zip archive for reading, returns *zip.ReadCloser
CreateZip(path) Creates a zip archive for writing, returns *ZipWriter

Tar

Function Description
Tar(src, dest) Archives a file or directory into a tar archive
Untar(src, dest) Extracts a tar archive into a directory
OpenTar(path) Opens a tar archive for reading, returns *TarReader
CreateTar(path) Creates a tar archive for writing, returns *TarWriter

Tar+Gzip

Function Description
TarGz(src, dest) Archives a file or directory into a gzip-compressed tar archive
UntarGz(src, dest) Extracts a gzip-compressed tar archive into a directory
OpenTarGz(path) Opens a gzip-compressed tar archive for reading, returns *TarGzReader
CreateTarGz(path) Creates a gzip-compressed tar archive for writing, returns *TarGzWriter

Gzip

Function Description
Gzip(src, dest) Compresses a file with gzip
Ungzip(src, dest) Decompresses a gzip-compressed file
OpenGzip(path) Opens a gzip-compressed file for reading, returns *GzipReader
CreateGzip(path) Creates a gzip-compressed file for writing, returns *GzipWriter

Zlib

Function Description
Zlib(src, dest) Compresses a file with zlib
Unzlib(src, dest) Decompresses a zlib-compressed file
OpenZlib(path) Opens a zlib-compressed file for reading, returns *ZlibReader
CreateZlib(path) Creates a zlib-compressed file for writing, returns *ZlibWriter

Flate

Raw DEFLATE data has no header identifying it, so it cannot be auto-detected by Decompress.

Function Description
Flate(src, dest) Compresses a file with raw DEFLATE
Unflate(src, dest) Decompresses a raw DEFLATE-compressed file
OpenFlate(path) Opens a raw DEFLATE-compressed file for reading, returns *FlateReader
CreateFlate(path) Creates a raw DEFLATE-compressed file for writing, returns *FlateWriter

Lzw

LZW streams carry no header identifying them, so they cannot be auto-detected by Decompress. The *With variants take explicit order/litWidth parameters; the plain functions use DefaultLzwOrder/DefaultLzwLitWidth.

Function Description
Lzw(src, dest) Compresses a file with LZW using the default order/litWidth
LzwWith(src, dest, order, litWidth) Compresses a file with LZW using explicit order/litWidth
Unlzw(src, dest) Decompresses an LZW-compressed file using the default order/litWidth
UnlzwWith(src, dest, order, litWidth) Decompresses an LZW-compressed file using explicit order/litWidth
OpenLzw(path) Opens an LZW-compressed file for reading, returns *LzwReader
OpenLzwWith(path, order, litWidth) Like OpenLzw with explicit order/litWidth
CreateLzw(path) Creates an LZW-compressed file for writing, returns *LzwWriter
CreateLzwWith(path, order, litWidth) Like CreateLzw with explicit order/litWidth

Bzip2

The standard library only implements a bzip2 reader, not a writer, so there is no Bzip2 compress function — only decompression is supported.

Function Description
Bunzip2(src, dest) Decompresses a bzip2-compressed file
OpenBzip2(path) Opens a bzip2-compressed file for reading, returns *Bzip2Reader

Auto-detection

Function Description
Decompress(src, dest) Detects the format of src (zip, tar, tar.gz, gzip, zlib or bzip2) from its content and extracts/decompresses it into dest; returns ErrUnknownFormat otherwise

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.

File Hashing

Computing and verifying file/directory content hashes:

Function Description
MD5(p) Computes MD5 hash of file/directory
ForceMD5(p) Like MD5, ignores errors
SHA1(p) Computes SHA1 hash of file/directory
ForceSHA1(p) Like SHA1, ignores errors
SHA256(p) Computes SHA256 hash of file/directory
ForceSHA256(p) Like SHA256, ignores errors
Checksum(p) Computes checksum (MD5) of file/directory
ForceChecksum(p) Like Checksum, ignores errors
Hash(p, h) Computes hash using provided hash.Hash
ForceHash(p, h) Like Hash, ignores errors
Size(p) Gets file size (bytes) or directory size (recursive)
ForceSize(p) Like Size, ignores errors
GetModTime(p) Gets file modification time
ForceGetModTime(p) Like GetModTime, ignores errors
GetInfo(p) Gets os.FileInfo for path
GetMode(p) Gets file permissions (os.FileMode)

Permissions & Ownership

Managing file permissions and ownership:

Function Description
SetMode(p, mode) Sets file permissions
Chmod(p, mode) Alias for SetMode
ChmodRecursive(p, mode) Sets permissions recursively
ForceChmodRecursive(p, mode) Like ChmodRecursive, ignores errors
SetModeRecursive(p, mode) Alias for ChmodRecursive
ForceSetModeRecursive(p, mode) Like SetModeRecursive, ignores errors
SetOwner(p, uid, gid) Changes file owner (uid/gid)
Chown(p, uid, gid) Alias for SetOwner
ChownRecursive(p, uid, gid) Changes ownership recursively
ForceChownRecursive(p, uid, gid) Like ChownRecursive, ignores errors
SetOwnerRecursive(p, uid, gid) Alias for ChownRecursive
ForceSetOwnerRecursive(p, uid, gid) Like SetOwnerRecursive, ignores errors
SetHidden(p, hidden) Hides/unhides file by renaming (Unix)
Hide(p) Hides file/directory
Unhide(p) Unhides file/directory

Creating and managing symbolic/hard links:

Function Description
Link(src, dst) Creates hard link from src to dst
Symlink(oldname, newname) Creates symbolic link
Readlink(p) Reads destination of symbolic link
ForceReadlink(p) Like Readlink, ignores errors

File System Operations

General file system operations:

Function Description
Copy(src, dst) Recursively copies file or directory
Move(src, dst) Moves/renames file or directory
Rename(old, new) Renames file or directory
Remove(p) Removes file or directory (recursive)
Empty(p) Empties file (truncates) or directory (removes contents)

File Watching

Monitoring file system changes:

Function Description
NewWatcher() Creates new file system watcher
Watch(ctx, p, callback) Watches single path for changes
WatchRecursive(ctx, p, callback) Watches directory and subdirectories
WatchGlob(ctx, dir, pattern, callback) Watches with glob pattern filtering

Watcher Methods

watcher, err := fsx.NewWatcher()
if err != nil {
  panic(err)
}
defer watcher.Close()

watcher.Add(path)          // Add path to watch list
watcher.Remove(path)       // Remove path from watch list
watcher.Has(path)          // Check if path is being watched
watcher.WatchList()        // Get list of watched paths
watcher.Watch(ctx, callback) // Start watching

Watch Events

Events contain:

  • Op - Operation type (bitmasked), check with event.Has(fsx.EvtCreate):
    • EvtCreate - File/directory created
    • EvtWrite - File written
    • EvtRemove - File/directory removed
    • EvtRename - File/directory renamed
    • EvtChmod - File permissions changed
    • EvtError - Error occurred
  • Path - Full path of file/directory that changed
  • Err - Error if Op contains EvtError

Path Anatomy

You can use GetPathParts or GetDirParts to extract all path information at once.

For the path /c/users/dev/fs/path.go:

Part Example Description
Absolute /c/users/dev/fs/path.go Complete absolute path
Base path.go File/directory name with extension
Name path File/directory name without extension
Ext .go Extension including dot
ExtName go Extension without dot
Parent /c/users/dev/fs Parent directory path
ParentName fs Parent directory name
Volume c: (Windows) / `` (Unix) Drive letter (Windows only)

PathParts Struct

type PathParts struct {
  Absolute   string // /c/users/dev/fs/path.go
  Base       string // path.go
  Name       string // path
  Ext        string // .go
  ExtName    string // go
  Parent     string // /c/users/dev/fs
  ParentName string // fs
  Volume     string // c: (Windows), "" (Unix)
}

// Get all parts at once
parts := fsx.GetPathParts("./path/to/file.go")
// or for directories
parts := fsx.GetDirParts("./path/to/dir")

Documentation

Index

Constants

View Source
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

View Source
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
)
View Source
var (
	EvtCreate = fsnotify.Create
	EvtRemove = fsnotify.Remove
	EvtWrite  = fsnotify.Write
	EvtRename = fsnotify.Rename
	EvtChmod  = fsnotify.Chmod
	EvtError  = fsnotify.Op(2048)
)
View Source
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.

View Source
var (
	PathSeparator = string(os.PathSeparator)
)

Functions

func AbsolutePath

func AbsolutePath(p string) (string, error)

AbsolutePath converts a path to an absolute path.

func AppendFile

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

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

func AppendFileJson(p string, v any) error

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

func AppendFileLines(p string, lines []string) error

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

func AppendFileString(p string, data string) error

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

func Bunzip2(src, dest string) error

Bunzip2 decompresses the bzip2-compressed source file into the destination file.

func Chdir

func Chdir(p string) error

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 Checksum

func Checksum(p string) (string, error)

Checksum computes the checksum (MD5) of a file or directory.

func Chmod

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

Chmod is an alias for SetMode.

func ChmodRecursive added in v0.1.0

func ChmodRecursive(p string, mode os.FileMode) error

ChmodRecursive recursively changes permissions for a directory and all its contents.

func Chown

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

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

func ChownRecursive(p string, uid, gid int) error

ChownRecursive recursively changes ownership for a directory and all its contents.

func CleanPath

func CleanPath(p string) string

CleanPath returns the shortest path equivalent to p by eliminating . and .. elements.

func Copy

func Copy(src, dst string) error

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

func CreateDir(p string) error

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

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

CreateFile creates a new file at the specified path. Alias for os.Create.

func CreateTempDir

func CreateTempDir(prefix string) (string, error)

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

func CreateTempFile(prefix string) (*os.File, error)

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

func Decompress(src, dest string) error

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 Empty

func Empty(p string) error

Empty empties a file (truncates to zero) or directory (removes all contents).

func EmptyDir

func EmptyDir(p string) error

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

func EnsureDir(p string) error

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

func EnsureFile(p string) error

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 Exists

func Exists(p string) bool

Exists checks if a file or directory exists at the given p.

func Flate added in v0.1.0

func Flate(src, dest string) error

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

func ForceAbsolutePath(p string) string

ForceAbsolutePath is like AbsolutePath but ignores errors and returns an empty string on error.

func ForceChecksum

func ForceChecksum(p string) string

ForceChecksum is like Checksum but ignores errors and returns an empty string on error.

func ForceChmodRecursive added in v0.1.0

func ForceChmodRecursive(p string, mode os.FileMode)

ForceChmodRecursive is like ChmodRecursive but ignores errors.

func ForceChownRecursive added in v0.1.0

func ForceChownRecursive(p string, uid, gid int)

ForceChownRecursive is like ChownRecursive but ignores errors.

func ForceCreateTempDir

func ForceCreateTempDir(prefix string) string

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

func ForceGetModTime(p string) time.Time

ForceGetModTime is like GetModTime but ignores errors and returns zero time on error.

func ForceGetParentDir

func ForceGetParentDir(p string) string

ForceGetParentDir is like GetParentDir but ignores errors and returns an empty string on error.

func ForceGetParentDirName

func ForceGetParentDirName(p string) string

ForceGetParentDirName is like GetParentDirName but ignores errors and returns an empty string on error.

func ForceGlob

func ForceGlob(dir string, pattern string) []string

ForceGlob is like Glob but ignores errors and returns an empty slice on error.

func ForceHash

func ForceHash(p string, h hash.Hash) string

ForceHash is like Hash but ignores errors and returns an empty string on error.

func ForceIsEmpty

func ForceIsEmpty(p string) bool

ForceIsEmpty is like IsEmpty but ignores errors and returns false on error.

func ForceIsHidden

func ForceIsHidden(p string) bool

ForceIsHidden is like IsHidden but ignores errors and returns false on error.

func ForceList

func ForceList(p string) []string

ForceList is like List but ignores errors and returns an empty slice on error.

func ForceListDirs

func ForceListDirs(p string) []string

ForceListDirs is like ListDirs but ignores errors and returns an empty slice on error.

func ForceListDirsRecursive

func ForceListDirsRecursive(p string) []string

ForceListDirsRecursive is like ListDirsRecursive but ignores errors and returns an empty slice on error.

func ForceListFiles

func ForceListFiles(p string) []string

ForceListFiles is like ListFiles but ignores errors and returns an empty slice on error.

func ForceListFilesRecursive

func ForceListFilesRecursive(p string) []string

ForceListFilesRecursive is like ListFilesRecursive but ignores errors and returns an empty slice on error.

func ForceListRecursive

func ForceListRecursive(p string) []string

ForceListRecursive is like ListRecursive but ignores errors and returns an empty slice on error.

func ForceMD5

func ForceMD5(p string) string

ForceMD5 is like MD5 but ignores errors and returns an empty string on error.

func ForceMatch

func ForceMatch(p, pattern string) bool

ForceMatch is like Match but ignores errors and returns false on error.

func ForceReadFile

func ForceReadFile(p string) []byte

ForceReadFile is like ReadFile but ignores errors and returns an empty slice on error.

func ForceReadFileJsonAs added in v0.1.0

func ForceReadFileJsonAs[T any](p string) T

ForceReadFileJsonAs is like ReadFileJsonAs but ignores errors and returns the zero value of type T on error.

func ForceReadFileLines

func ForceReadFileLines(p string) []string

ForceReadFileLines is like ReadFileLines but ignores errors and returns an empty slice on error.

func ForceReadFileString

func ForceReadFileString(p string) string

ForceReadFileString is like ReadFileString but ignores errors and returns an empty string on error.

func ForceReadlink(p string) string

ForceReadlink is like Readlink but ignores errors and returns an empty string on error.

func ForceRelativePath

func ForceRelativePath(base, target string) string

ForceRelativePath is like RelativePath but ignores errors and returns the target path on error.

func ForceSHA1

func ForceSHA1(p string) string

ForceSHA1 is like SHA1 but ignores errors and returns an empty string on error.

func ForceSHA256

func ForceSHA256(path string) string

ForceSHA256 is like SHA256 but ignores errors and returns an empty string on error.

func ForceSetModeRecursive added in v0.1.0

func ForceSetModeRecursive(p string, mode os.FileMode)

ForceSetModeRecursive is like SetModeRecursive but ignores errors.

func ForceSetOwnerRecursive added in v0.1.0

func ForceSetOwnerRecursive(p string, uid, gid int)

ForceSetOwnerRecursive is like SetOwnerRecursive but ignores errors.

func ForceSize

func ForceSize(p string) int64

ForceSize is like Size but ignores errors and returns 0 on error.

func ForceTouchTempFile added in v0.1.0

func ForceTouchTempFile(prefix string) string

ForceTouchTempFile is like TouchTempFile but ignores errors and returns an empty string on error.

func FromBackslashPath

func FromBackslashPath(p string) string

FromBackslashPath converts backslashes to forward slashes.

func FromSlashPath

func FromSlashPath(p string) string

FromSlashPath converts forward slashes to the OS-specific separator.

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the cache directory of the current user.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the configuration directory of the current user.

func GetCurrentDir

func GetCurrentDir() (string, error)

GetCurrentDir is an alias for Getwd.

func GetHomeDir

func GetHomeDir() (string, error)

GetHomeDir returns the home directory of the current user.

func GetInfo

func GetInfo(p string) (os.FileInfo, error)

GetInfo returns a FileInfo describing the file at the specified path. If the path does not exist, it returns an error.

func GetModTime

func GetModTime(p string) (time.Time, error)

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

func GetMode(p string) (os.FileMode, error)

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

func GetParentDir(p string) (string, error)

GetParentDir returns the parent directory of a file or directory path.

func GetParentDirName

func GetParentDirName(p string) (string, error)

GetParentDirName returns the name of the parent directory of a file or directory path.

func GetPathBase

func GetPathBase(p string) string

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

func GetPathExtension(p string) string

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

func GetPathExtensionName(p string) string

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

func GetPathName(p string) string

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

func GetPathParent(p string) string

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

func GetPathParentName(p string) string

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

func GetPathVolume(p string) string

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 GetPwd added in v0.1.0

func GetPwd() (string, error)

Getwd returns the current working directory.

func GetTempDir

func GetTempDir() string

GetTempDir returns the default temporary directory of the system.

func Glob

func Glob(dir, pattern string) ([]string, error)

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

func Gzip(src, dest string) error

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

func HasExtensionPath(p string) bool

HasExtensionPath checks if a path has a file extension.

func Hash

func Hash(p string, h hash.Hash) (string, error)

Hash computes the hash of a file or directory using the provided hash function.

func Hide

func Hide(p string) error

Hide hides a file or directory by renaming it to a dot-prefixed name.

func IsAbsolutePath

func IsAbsolutePath(p string) bool

IsAbsolutePath checks if a path is absolute.

func IsBackslashPath

func IsBackslashPath(p string) bool

IsBackslashPath checks if a path contains backslashes.

func IsDir

func IsDir(p string) bool

IsDir checks if the given p is a directory. If the p does not exist or is a file, it returns false.

func IsEmpty

func IsEmpty(p string) (bool, error)

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

func IsExecutable(p string) bool

IsExecutable checks if a file at the specified path is executable.

func IsFile

func IsFile(p string) bool

IsFile checks if the given p is a file. If the p does not exist or is a directory, it returns false.

func IsHidden

func IsHidden(p string) (bool, error)

IsHidden checks if a file or directory is hidden (starts with a dot on Unix-like systems).

func IsPatternValid

func IsPatternValid(pattern string) bool

IsPatternValid checks if the given glob pattern is valid.

func IsReadable

func IsReadable(p string) bool

IsReadable checks if a file at the specified path is readable.

func IsSame

func IsSame(p1, p2 string) bool

IsSame checks if two paths refer to the same file by comparing their inode information.

func IsSlashPath

func IsSlashPath(p string) bool

IsSlashPath checks if a path contains forward slashes.

func IsWritable

func IsWritable(p string) bool

IsWritable checks if a file at the specified path is writable.

func JoinPath

func JoinPath(elem ...string) string

JoinPath joins path elements using the OS-specific path separator.

func JoinPathLinux

func JoinPathLinux(elem ...string) string

JoinPathLinux joins path elements using forward slashes (Unix-style).

func JoinPathWindows

func JoinPathWindows(elem ...string) string

JoinPathWindows joins path elements using backslashes (Windows-style).

func JoinPathWith

func JoinPathWith(sep string, elem ...string) string

JoinPathWith joins path elements using a specific separator.

func Link(src, dst string) error

Link creates a hard link from src to dst. If src does not exist or dst already exists, it returns an error.

func List

func List(p string) ([]string, error)

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

func ListDirs(p string) ([]string, error)

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

func ListDirsRecursive(p string) ([]string, error)

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

func ListFiles(p string) ([]string, error)

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

func ListFilesRecursive(p string) ([]string, error)

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

func ListRecursive(p string) ([]string, error)

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

func Lzw(src, dest string) error

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

func LzwWith(src, dest string, order lzw.Order, litWidth int) error

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 MD5

func MD5(p string) (string, error)

MD5 computes the MD5 hash of a file or directory.

func Match

func Match(p, pattern string) (bool, error)

Match checks if a path matches the given glob pattern.

func Move

func Move(src, dst string) error

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

func OpenFile(p string) (*os.File, error)

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 Pwd

func Pwd() (string, error)

Pwd is an alias for Getwd.

func ReadFile

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

ReadFile reads the entire content of a file and returns it as a byte slice.

func ReadFileJson

func ReadFileJson(p string, v any) error

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

func ReadFileJsonAs[T any](p string) (T, error)

ReadFileJsonAs reads a JSON file and unmarshals it into a value of type T, returning the result with type safety.

func ReadFileLines

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

ReadFileLines reads a file and returns its content as a slice of strings, where each string represents a line in the file.

func ReadFileString

func ReadFileString(p string) (string, error)

ReadFileString reads the entire content of a file and returns it as a string.

func Readlink(p string) (string, error)

Readlink returns the destination of the named symbolic link.

func RelativePath

func RelativePath(base, target string) (string, error)

RelativePath returns the relative path from base to target.

func Remove

func Remove(p string) error

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

func Rename(oldPath, newPath string) error

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

func ReplaceInFile(p string, old []byte, new []byte) error

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

func ReplaceInFileString(p string, old string, new string) error

ReplaceInFileString is like ReplaceInFile but works with strings instead of byte slices.

func SHA1

func SHA1(p string) (string, error)

SHA1 computes the SHA1 hash of a file or directory.

func SHA256

func SHA256(path string) (string, error)

SHA256 computes the SHA256 hash of a file or directory.

func SetHidden

func SetHidden(p string, hidden bool) error

SetHidden sets the hidden status of a file or directory by renaming it to/from a dot-prefixed name.

func SetMode

func SetMode(p string, mode os.FileMode) error

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

func SetModeRecursive(p string, mode os.FileMode) error

SetModeRecursive recursively sets the file mode (permissions) for a directory and all its contents.

func SetOwner

func SetOwner(p string, uid, gid int) error

SetOwner changes the ownership of a file (alias for Chown).

func SetOwnerRecursive added in v0.1.0

func SetOwnerRecursive(p string, uid, gid int) error

SetOwnerRecursive recursively changes ownership for a directory and all its contents.

func Size

func Size(p string) (int64, error)

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 SplitPath

func SplitPath(p string) []string

SplitPath splits a path into its components using forward slashes.

func Symlink(oldname, newname string) error

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

func Tar(src, dest string) error

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

func TarGz(src, dest string) error

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

func ToBackslashPath(p string) string

ToBackslashPath converts forward slashes to backslashes.

func ToSlashPath

func ToSlashPath(p string) string

ToSlashPath converts the path to use forward slashes.

func TouchFile

func TouchFile(p string) error

TouchFile creates an empty file at the specified path if it does not already exist.

func TouchTempFile added in v0.1.0

func TouchTempFile(prefix string) (string, error)

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

func TruncateFile(p string, size int64) error

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

func Unflate(src, dest string) error

Unflate decompresses the raw DEFLATE-compressed source file into the destination file.

func Ungzip added in v0.1.0

func Ungzip(src, dest string) error

Ungzip decompresses the gzip-compressed source file into the destination file.

func Unhide

func Unhide(p string) error

Unhide unhides a file or directory by removing its dot prefix.

func Unlzw added in v0.1.0

func Unlzw(src, dest string) error

Unlzw decompresses the LZW-compressed source file into the destination file, using DefaultLzwOrder and DefaultLzwLitWidth.

func UnlzwWith added in v0.1.0

func UnlzwWith(src, dest string, order lzw.Order, litWidth int) error

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

func Untar(src, dest string) error

Untar extracts the contents of a tar archive at the source path into the destination directory.

func UntarGz added in v0.1.0

func UntarGz(src, dest string) error

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

func Unzip(src, dest string) error

Unzip extracts the contents of a zip archive at the source path into the destination directory.

func Unzlib added in v0.1.0

func Unzlib(src, dest string) error

Unzlib decompresses the zlib-compressed source file into the destination file.

func Walk

func Walk(p string, fn func(string) error) error

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

func Watch(ctx context.Context, p string, callback func(event Event)) error

Watch watches a single path for file system events and calls the callback for each event.

func WatchGlob

func WatchGlob(ctx context.Context, dir string, pattern string, callback func(event Event)) error

WatchGlob watches a directory and filters events by a glob pattern. The pattern is matched against paths relative to the directory.

func WatchRecursive

func WatchRecursive(ctx context.Context, p string, callback func(event Event)) error

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

func WriteFile(p string, data []byte) error

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

func WriteFileAtomic(p string, data []byte) error

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

func WriteFileJson(p string, v any) error

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

func WriteFileJsonAtomic(p string, v any) error

WriteFileJsonAtomic is like WriteFileAtomic but marshals a value to JSON first.

func WriteFileLines

func WriteFileLines(p string, lines []string) error

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

func WriteFileLinesAtomic(p string, lines []string) error

WriteFileLinesAtomic is like WriteFileAtomic but accepts a slice of strings (lines).

func WriteFileString

func WriteFileString(p string, data string) error

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

func WriteFileStringAtomic(p string, data string) error

WriteFileStringAtomic is like WriteFileAtomic but accepts a string.

func Zip added in v0.1.0

func Zip(src, dest string) error

Zip compresses the source file or directory into a zip 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 Zlib added in v0.1.0

func Zlib(src, dest string) error

Zlib compresses the source file into a zlib-compressed file at the destination path. src must be a file; if it is a directory, it returns ErrIsDir.

Types

type Bzip2Reader added in v0.1.0

type Bzip2Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

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 Event

type Event struct {
	Op   fsnotify.Op
	Path string
	Err  error
}

func (Event) Has

func (e Event) Has(op fsnotify.Op) bool

func (Event) String

func (e Event) String() string

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

type FlateWriter struct {
	*flate.Writer
	// contains filtered or unexported fields
}

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

type GzipReader struct {
	*gzip.Reader
	// contains filtered or unexported fields
}

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

type GzipWriter struct {
	*gzip.Writer
	// contains filtered or unexported fields
}

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

func OpenLzw(path string) (*LzwReader, error)

OpenLzw opens the LZW-compressed file at the specified path for reading, using DefaultLzwOrder and DefaultLzwLitWidth.

func OpenLzwWith added in v0.1.0

func OpenLzwWith(path string, order lzw.Order, litWidth int) (*LzwReader, error)

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.

func (*LzwReader) Close added in v0.1.0

func (r *LzwReader) Close() error

Close closes the LZW stream and the underlying 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

func CreateLzw(path string) (*LzwWriter, error)

CreateLzw creates a new LZW-compressed file at the specified path for writing, using DefaultLzwOrder and DefaultLzwLitWidth.

func CreateLzwWith added in v0.1.0

func CreateLzwWith(path string, order lzw.Order, litWidth int) (*LzwWriter, error)

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].

func (*LzwWriter) Close added in v0.1.0

func (w *LzwWriter) Close() error

Close flushes and closes the LZW stream, then closes the underlying file.

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

func GetDirParts(p string) PathParts

GetDirParts returns all path components for a directory as a PathParts struct.

func GetPathParts

func GetPathParts(p string) PathParts

GetPathParts returns a PathParts struct containing various components of the given path.

type TarGzReader added in v0.1.0

type TarGzReader struct {
	*tar.Reader
	// contains filtered or unexported fields
}

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

type TarGzWriter struct {
	*tar.Writer
	// contains filtered or unexported fields
}

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

type TarReader struct {
	*tar.Reader
	// contains filtered or unexported fields
}

TarReader reads a tar archive from a file, closing both the tar stream and the underlying file on Close.

func OpenTar added in v0.1.0

func OpenTar(path string) (*TarReader, error)

OpenTar opens the tar archive at the specified path for reading.

func (*TarReader) Close added in v0.1.0

func (r *TarReader) Close() error

Close closes the underlying file.

type TarWriter added in v0.1.0

type TarWriter struct {
	*tar.Writer
	// contains filtered or unexported fields
}

TarWriter writes a tar archive to a file, closing both the tar stream and the underlying file on Close.

func CreateTar added in v0.1.0

func CreateTar(path string) (*TarWriter, error)

CreateTar creates a new tar archive at the specified path for writing.

func (*TarWriter) Close added in v0.1.0

func (w *TarWriter) Close() error

Close flushes and closes the tar stream, then closes the underlying file.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher creates a new file system watcher.

func (*Watcher) Add

func (w *Watcher) Add(p string) error

func (*Watcher) Close

func (w *Watcher) Close() error

func (*Watcher) Has

func (w *Watcher) Has(path string) bool

func (*Watcher) Remove

func (w *Watcher) Remove(p string) error

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, callback func(event Event)) error

Watch starts watching for file system events and calls the callback for each event.

func (*Watcher) WatchList

func (w *Watcher) WatchList() []string

type ZipWriter added in v0.3.0

type ZipWriter struct {
	*zip.Writer
	// contains filtered or unexported fields
}

ZipWriter writes a zip archive to a file, closing both the zip stream and the underlying file on Close.

func CreateZip added in v0.1.0

func CreateZip(path string) (*ZipWriter, error)

CreateZip creates a new zip archive at the specified path for writing.

func (*ZipWriter) Close added in v0.3.0

func (w *ZipWriter) Close() error

Close flushes and closes the zip stream, then closes the underlying file.

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

type ZlibWriter struct {
	*zlib.Writer
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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