textar

package module
v0.250708.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: 0BSD Imports: 7 Imported by: 3

README

textar: TEXTual ARchive

Package textar encodes a file list (key-value slice) into a human editable text file and vice versa. See https://pkg.go.dev/github.com/ypsu/textar for the documentation.

Note: this project uses https://ypsu.github.io/featver as its versioning scheme. The project will enter the more stable v1 version only when it has users already.

Comes with a command line tool as well, check out https://pkg.go.dev/github.com/ypsu/textar/bin/textar.

Documentation

Overview

Package textar encodes a file list (key-value slice) into a human editable text file and vice versa. This is inspired by https://pkg.go.dev/golang.org/x/tools/txtar but this format can encode any content perfectly without issues. Go's txtar doesn't handle newlines and content containing txtar markers well. In textar each file is encoded via "[SEP] [NAME]\n[CONTENT]\n". SEP is two or more = signs. The first SEP can be arbitrary length, the rest must be the same length. The first line beginning with == determines the separator length. The dynamic SEP-length makes it possible to encode and decode anything perfectly. This is the main advantage over Go's txtar. Furthermore anything before the first SEP is a free form comment. Example:

Some comments here.

=== file1
file1 content.

=== file2
file2 content.
== file3
this is a textar within textar.

The separator here is === so this textar contains file1 and file2. file3 is not part of the main textar, it just shows that file2 could be a textar itself.

The Archive.Format function automatically picks a separator length that is unique and won't conflict with existing file values. Use Parse to parse it back.

See https://github.com/ypsu/textar/blob/main/example/seq.textar for a longer example. See the testdata directory of https://github.com/ypsu/pkgtrim for a more realistic example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive added in v0.250524.0

type Archive struct {
	Comment []byte
	Files   []File
}

An Archive is a collection of files.

func Parse

func Parse(data []byte) *Archive

Parse parses the serialized form of an Archive. The returned Archive holds slices of data.

func ParseFile added in v0.250524.0

func ParseFile(file string) (*Archive, error)

ParseFile parses the named file as an archive.

func (*Archive) FS added in v0.250524.0

func (a *Archive) FS() fstest.MapFS

FS returns an object implementing io/fs.FS built from the contents of an archive. This is a helper function for tests.

func (*Archive) Format added in v0.250524.0

func (a *Archive) Format() []byte

Format an archive into a byte stream with custom settings.

func (*Archive) Range added in v0.250524.0

func (a *Archive) Range() iter.Seq2[string, []byte]

Range iterates over the Files.

type File

type File struct {
	Name string
	Data []byte
}

A File is a single file in an archive.

Directories

Path Synopsis
bin
textar
textar converts to and extracts from textar files.
textar converts to and extracts from textar files.
The seq command demonstrates the usage of the textar library, see seq.textar for the details.
The seq command demonstrates the usage of the textar library, see seq.textar for the details.

Jump to

Keyboard shortcuts

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