go-file-utils is an idiomatic, high-performance Go filesystem library designed to bridge the gap between low-level os/io primitives and daily production development tasks.
os, io, path/filepath, archive/zip, archive/tar, crypto/*).\) and POSIX/Unix (/).../../) inside archives by sanitizing target extraction paths.:, *, ?, ", <, >, |, /, \).WithTempDir, WithTempFile, WithLock) guarantee automatic resource release via Go defer mechanics.+---------------------------------------------------------------------------------------+
| Client Application |
+---------------------------------------------------------------------------------------+
|
v
+---------------------------------------------------------------------------------------+
| go-file-utils API |
+---------------------------------------------------------------------------------------+
| | | | |
v v v v v
[ Core FS ] [ Atomic/Stream ] [ Finder ] [ Archive ] [ Lock & Temp ]
- Exists - WriteFileAtomic - Find - Zip (ZipSlip) - WithLock
- CopyFile - AppendToFile - FindByName - Unzip - FileLock
- CopyDir - ReadLines - FindByExt - TarGz - WithTempDir
- Move - CopyWithProgress - Size/Date/Reg - UntarGz - Sanitize
- Touch - Line-by-Line - Depth control - WithTempFile
| | | | |
+---------------------------------------------------------------------------------------+
| Go Standard Library |
| (os, io, path/filepath, bufio, crypto/*, archive/zip, archive/tar) |
+---------------------------------------------------------------------------------------+
fileutil.go)Exists, IsFile, IsDir, IsSymlink, IsEmptyDir, GetInfo, GetDirSize.EnsureDir and EnsureParentDir (recursive directory creation), EmptyDir.Touch, RemoveIfExists, CopyFile (with timestamp preservation and buffer tuning), CopyDir, Move.stream.go)WriteFileAtomic writes into a sibling hidden temporary file, flushes dirty pages with Sync(), chmods, and atomically renames.AppendToFile safely ensures parent directories and writes with O_APPEND.ReadLines processes large files line by line using an early-exit callback pattern to avoid storing the entire file in RAM; ReadLinesAll offers convenience.CopyWithProgress streams bytes between io.Reader and io.Writer while invoking a progress callback with (bytesCopied, totalBytes).finder.go)Find supports a rich declarative SearchFilter:
PatternRegexExtensions (case-insensitive)MinSize and MaxSize filtersModifiedAfter and ModifiedBefore time windowsMaxDepth restrictionSkipHidden flag for dotfilesarchive.go).zip and .tar.gz formats.sanitizeArchivePath enforces strict directory root boundaries, catching path traversal attacks (../../) before writing to disk.hash.go)MD5, SHA1, SHA256, and SHA512 without reading entire files into memory.VerifyFileChecksum provides quick validation against known hashes.temp.go, lock.go)WithTempDir and WithTempFile manage temporary lifecycles reliably.FileLock provides atomic mutual exclusion across processes or workers using O_CREATE|O_EXCL lock files with customizable timeouts.