txtar

package
v0.0.0-...-691c0ea Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ProgName is the implicit program name written to the temp
	// dir and used in compiler and vet errors.
	ProgName     = "main.go"
	ProgTestName = "prog_test.go"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSet

type FileSet struct {
	Files []string // filenames in user-provided order
	// contains filtered or unexported fields
}

FileSet is a set of files. The zero value for FileSet is an empty set ready to use.

func SplitFiles

func SplitFiles(src []byte) (*FileSet, error)

SplitFiles splits the user's input program src into 1 or more files, splitting it based on boundaries as specified by the "txtar" format. It returns an error if any filenames are bogus or duplicates. The implicit filename for the txtar comment (the lines before any txtar separator line) are named "main.go". It is an error to have an explicit file named "main.go" in addition to having the implicit "main.go" file (non-empty comment section).

The filenames are validated to only be relative paths, not too long, not too deep, not have ".." elements, not have backslashes or low ASCII binary characters, and to be in path.Clean canonical form.

SplitFiles takes ownership of src.

func (*FileSet) AddFile

func (fs *FileSet) AddFile(filename string, src []byte)

AddFile adds a file to fs. If fs already contains filename, its contents are replaced.

func (*FileSet) Contains

func (fs *FileSet) Contains(filename string) bool

Contains reports whether fs contains the given filename.

func (*FileSet) Data

func (fs *FileSet) Data(filename string) []byte

Data returns the content of the named file. The fileSet retains ownership of the returned slice.

func (*FileSet) Format

func (fs *FileSet) Format() []byte

Format returns fs formatted as a txtar archive.

func (*FileSet) Map

func (fs *FileSet) Map() map[string][]byte

Map returns the map of files in the set.

func (*FileSet) MvFile

func (fs *FileSet) MvFile(source, target string)

func (*FileSet) Num

func (fs *FileSet) Num() int

Num returns the number of files in the set.

func (*FileSet) Update

func (fs *FileSet) Update(filename string, src []byte)

Jump to

Keyboard shortcuts

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