Extended implementation of the txtar archive format
0

Configure Feed

Select the types of activity you want to include in your feed.

Go 97.2%
Other 2.8%
78 1 8

Clone this repository

https://tangled.org/followtheprocess.codes/txtar https://tangled.org/did:plc:rrramy6at4xhwpmvfdbjcvbu
git@tangled.org:followtheprocess.codes/txtar git@tangled.org:did:plc:rrramy6at4xhwpmvfdbjcvbu

For self-hosted knots, clone URLs may differ based on your setup.



README.md

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.