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 without issues. Each file in a textar is encoded via "[SEP] [NAME]\n[CONTENT]\n". The first SEP in the file determines the SEP for the whole file. SEP cannot contain space or newline. Example:
== file1 file1 content == file2 file2 content == # some comment some comment body. == file3 file3 content.
The separator here is == because that's how the archive starts. The Format function automatically picks a separator that is unique and won't conflict with existing file values. Use Parse to parse it back into a slice of File entries.
By default textar skips parsing entries starting with #. They can be used as comments. This behavior can be altered with ParseOptions.
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 ¶
func FS ¶ added in v0.240823.0
FS returns an object implementing io/fs.FS built from the contents of an archive. This is a helper function for tests.
Types ¶
type File ¶
File represents a single entry in the text archive.
func Parse ¶
Parse data with the default settings. Note by default textar skips entries that start with the # comment marker. Use ParseOptions to alter this.
type FormatOptions ¶
type FormatOptions struct { // The byte which gets repeated and then used to separate the Files. // Defaults to '=' if unspecified or set to an invalid value. Separator byte // Format appends the resulting data to this buffer. // Use this to reduce memory allocations. // Don't use it for concatenating textars, it won't work. Buffer []byte }
FormatOptions allows customizing the formatting.
func (FormatOptions) Format ¶
func (fo FormatOptions) Format(archive []File) []byte
Format an archive into a byte stream with custom settings.
type ParseOptions ¶
type ParseOptions struct { // If true, textar won't skip entries that have a name starting with # or have an empty name. ParseComments bool // Parse appends the resulting Files to this buffer. Buffer []File }
ParseOptions allows customizing the parsing.
func (ParseOptions) Parse ¶
func (po ParseOptions) Parse(data []byte) []File
Parse data with custom settings.
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. |