txtar

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSet

type FileSet struct {
	ProgName string            // default prog name
	Files    []string          // filenames in user-provided order
	M        map[string][]byte // filename -> source
	NoHeader bool              // whether the prog.go entry was implicit
}

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

func SplitFiles

func SplitFiles(src []byte, progName string) (*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 "prog.go". It is an error to have an explicit file named "prog.go" in addition to having the implicit "prog.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) 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)

type FileSystem

type FileSystem struct {
	Fset *FileSet
	Sys  fs.FS
}

func FS

func FS(fs *FileSet, filter func(file string) bool) (*FileSystem, error)

func (*FileSystem) Abs

func (f *FileSystem) Abs(path string) (string, error)

func (*FileSystem) Base

func (f *FileSystem) Base(filename string) string

func (*FileSystem) Join

func (f *FileSystem) Join(elem ...string) string

func (*FileSystem) ReadDir

func (f *FileSystem) ReadDir(dirname string) ([]fs.DirEntry, error)

func (*FileSystem) ReadFile

func (f *FileSystem) ReadFile(filename string) ([]byte, error)

Jump to

Keyboard shortcuts

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