txtar is a Go package and CLI tool for the txtar archive format, forked from golang.org/x/tools/txtar.
This project extends the original library with significant enhancements, including:
- Read/Write Library: Adds support for modifying archives programmatically (
Set,Delete). - Extended Filesystem: Implements a full
fs.FSinterface with write capabilities (Create,Remove,Rename), which the original library lacks. - Streaming Version: Creating a streaming version for efficient processing of large archives.
- CLI Version: A comprehensive command-line tool for creating, extracting, and managing archives.
go install github.com/username/txtar/cmd/txtar@latestThe txtar CLI provides commands to manage txtar archives.
Create a new archive from files or directories.
txtar create -r directory > archive.txtarFlags:
-r, --recursive: Recursive (default: false)-t, --trim: Trim directory prefix (default: false)--name: Name filter (glob pattern)--depth: Max depth
List files in an archive.
txtar list archive.txtarAdd files to an existing archive.
txtar add archive.txtar file1 file2Delete files from an archive.
txtar delete archive.txtar file1Extract content or display the archive.
# Display archive content
txtar cat archive.txtar
# Extract file content
txtar cat -t archive.txtar file1The Archive struct now supports direct modification:
a := new(txtar.Archive)
a.Set("file.txt", []byte("content"))
a.Delete("file.txt")The library provides a filesystem implementation that supports standard fs.FS operations as well as write operations:
fsys, err := txtar.FS(a)
// Create a new file within the archive
w, err := fsys.Create("file.txt")
if err != nil {
log.Fatal(err)
}
w.Write([]byte("content"))
w.Close()
// Read the file using standard fs.FS
data, err := fs.ReadFile(fsys, "file.txt")BSD-style (see LICENSE).