txtar

Imports

Imports #

"bytes"
"fmt"
"os"
"strings"

Constants & Variables

marker var #

var marker = *ast.CallExpr

markerEnd var #

var markerEnd = *ast.CallExpr

newlineMarker var #

var newlineMarker = *ast.CallExpr

Structs

Archive struct #

An Archive is a collection of files.

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

File struct #

A File is a single file in an archive.

type File struct {
Name string
Data []byte
}

Functions

Format function #

Format returns the serialized form of an Archive. It is assumed that the Archive data structure is well-formed: a.Comment and all a.File[i].Data contain no file marker lines, and all a.File[i].Name is non-empty.

func Format(a *Archive) []byte

Parse function #

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

func Parse(data []byte) *Archive

ParseFile function #

ParseFile parses the named file as an archive.

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

findFileMarker function #

findFileMarker finds the next file marker in data, extracts the file name, and returns the data before the marker, the file name, and the data after the marker. If there is no next marker, findFileMarker returns before = fixNL(data), name = "", after = nil.

func findFileMarker(data []byte) (before []byte, name string, after []byte)

fixNL function #

If data is empty or ends in \n, fixNL returns data. Otherwise fixNL returns a new slice consisting of data with a final \n added.

func fixNL(data []byte) []byte

isMarker function #

isMarker checks whether data begins with a file marker line. If so, it returns the name from the line and the data after the line. Otherwise it returns name == "" with an unspecified after.

func isMarker(data []byte) (name string, after []byte)

Generated with Arrow