Skip to content

Repository files navigation

txtar

License Go Reference Go Report Card GitHub CI codecov

An extended reimplementation of the txtar archive format 📂

Project Description

Package txtar re-implements and extends the original [golang.org/x/tools/txtar] package, making a number of modifications and (hopefully) improvements to the package.

No modifications are made to the txtar syntax, all txtar archives produced with this package are compatible with the original.

Improvements include:

  • Files stored in the archive may be looked up by name and operated on individually
  • Methods and functions are provided to help easily facilitate individual file editing
  • An ergonomic API for constructing an archive, rather than simply exposing struct fields
  • File names and contents are stored with all leading and trailing whitespace trimmed so that formatting the archive is easier and more consistent
  • Parsing an archive from its serialised format can error in the presence of a malformed document
  • Parse accepts an io.Reader rather than a []byte for greater flexibility
  • Dump is provided to serialise an archive to an io.Writer

Installation

go get go.followtheprocess.codes/txtar@latest

Quickstart

package main

import (
    "fmt"
    "log"
    "os"

    "go.followtheprocess.codes/txtar"
)

func main() {
    file, err := os.Open("archive.txtar")
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    archive, err := txtar.Parse(file)
    if err != nil {
        log.Fatal(err)
    }

    // Do things with the archive
    fmt.Println(archive.Comment())
    for name, contents := range archive.Files() {
        fmt.Printf("file: %s\ncontents: %s\n", name, contents)
    }
}

Credits

Inspired and adapted from the original source https://pkg.go.dev/golang.org/x/tools/txtar, all credit to the original Go Authors. Licensed under BSD-3-Clause.

About

An extended implementation of the https://pkg.go.dev/golang.org/x/tools/txtar archive format

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages