Documentation ¶
Index ¶
- Constants
- Variables
- func AllEqual(r []Record, s []Record) bool
- func Concat(w RecordWriter, r RecordReader, transform func(Record) Record) error
- func CreateFile(f Record) error
- func CreateFileInRoot(f Record, rootDir string) error
- func Equal(r Record, s Record) bool
- func ForEachRecord(rr RecordReader, fun func(Record) error) error
- func LSInfoFromRecord(rec Record) ls.FileInfo
- func MakeAllReproducible(files []Record)
- func NewLazyFile(name string) io.ReaderAt
- func Normalize(path string) string
- func Passthrough(r RecordReader, w RecordWriter) error
- func ReaderAtEqual(r1, r2 io.ReaderAt) bool
- func WriteRecords(w RecordWriter, files []Record) error
- func WriteTrailer(w RecordWriter) error
- type Archive
- type DedupWriter
- type EOFReader
- type Info
- type Record
- func CharDev(name string, perm uint64, rmajor, rminor uint64) Record
- func Directory(name string, mode uint64) Record
- func GetRecord(path string) (Record, error)
- func MakeReproducible(r Record) Record
- func ReadAllRecords(rr RecordReader) ([]Record, error)
- func StaticFile(name string, content string, perm uint64) Record
- func StaticRecord(contents []byte, info Info) Record
- func Symlink(name string, target string) Record
- type RecordFormat
- type RecordReader
- type RecordWriter
Constants ¶
const Trailer = "TRAILER!!!"
Trailer is the name of the trailer record.
Variables ¶
var (
Debug = func(string, ...interface{}) {}
)
var TrailerRecord = StaticRecord(nil, Info{Name: Trailer})
TrailerRecord is the last record in any CPIO archive.
Functions ¶
func Concat ¶
func Concat(w RecordWriter, r RecordReader, transform func(Record) Record) error
Concat reads files from r one at a time, and writes them to w.
func CreateFile ¶
func CreateFileInRoot ¶
func ForEachRecord ¶
func ForEachRecord(rr RecordReader, fun func(Record) error) error
ForEachRecord reads every record from r and applies f.
func LSInfoFromRecord ¶
LSInfoFromRecord converts a Record to be usable with the ls package for listing files.
func MakeAllReproducible ¶
func MakeAllReproducible(files []Record)
MakeAllReproducible makes all given records reproducible as in MakeReproducible.
func NewLazyFile ¶
func Passthrough ¶
func Passthrough(r RecordReader, w RecordWriter) error
Passthrough copies from a RecordReader to a RecordWriter It processes one record at a time to minimize the memory footprint.
func ReaderAtEqual ¶
func WriteRecords ¶
func WriteRecords(w RecordWriter, files []Record) error
WriteRecords writes multiple records.
Types ¶
type Archive ¶
type Archive struct { // Files is a map of relative archive path -> record. Files map[string]Record // Order is a list of relative archive paths and represents the order // in which Files were added. Order []string }
Archive implements RecordWriter and is an in-memory list of files.
Archive.Reader returns a RecordReader for this archive.
func ArchiveFromRecords ¶
func ReadArchive ¶
func ReadArchive(rr RecordReader) (*Archive, error)
ReadArchive reads the entire archive in-memory and makes it accessible by paths.
func (*Archive) Reader ¶
func (a *Archive) Reader() RecordReader
Reader returns a RecordReader for the archive that starts at the first record.
func (*Archive) WriteRecord ¶
WriteRecord implements RecordWriter and adds a record to the archive.
type DedupWriter ¶
type DedupWriter struct {
// contains filtered or unexported fields
}
DedupWriter is a RecordWriter that does not write more than one record with the same path.
There seems to be no harm done in stripping duplicate names when the record is written, and lots of harm done if we don't do it.
func (*DedupWriter) WriteRecord ¶
func (dw *DedupWriter) WriteRecord(rec Record) error
WriteRecord implements RecordWriter.
If rec.Name was already seen once before, it will not be written again and WriteRecord returns nil.
type EOFReader ¶
type EOFReader struct {
RecordReader
}
EOFReader is a RecordReader that converts the Trailer record to io.EOF.
func (EOFReader) ReadRecord ¶
ReadRecord implements RecordReader.
ReadRecord returns io.EOF when the record name is TRAILER!!!.
type Info ¶
type Info struct { Ino uint64 Mode uint64 UID uint64 GID uint64 NLink uint64 MTime uint64 FileSize uint64 Dev uint64 Major uint64 Minor uint64 Rmajor uint64 Rminor uint64 Name string }
Info holds metadata about files.
type Record ¶
type Record struct { // ReaderAt contains the content of this CPIO record. io.ReaderAt // Info is metadata describing the CPIO record. Info }
Record represents a CPIO record, which represents a Unix file.
func MakeReproducible ¶
MakeReproducible changes any fields in a Record such that if we run cpio again, with the same files presented to it in the same order, and those files have unchanged contents, the cpio file it produces will be bit-for-bit identical. This is an essential property for firmware-embedded payloads.
func ReadAllRecords ¶
func ReadAllRecords(rr RecordReader) ([]Record, error)
ReadAllRecords returns all records in `r` in the order in which they were read.
func StaticRecord ¶
type RecordFormat ¶
type RecordFormat interface { Reader(r io.ReaderAt) RecordReader Writer(w io.Writer) RecordWriter }
A RecordFormat gives readers and writers for dealing with archives from io objects.
var ( // Newc is the newc CPIO record format. Newc RecordFormat = newc{/* contains filtered or unexported fields */} )
func Format ¶
func Format(name string) (RecordFormat, error)
Format returns the RecordFormat with that name, if it exists.
type RecordReader ¶
A RecordReader reads one record from an archive.
type RecordWriter ¶
A RecordWriter writes one record to an archive.
func NewDedupWriter ¶
func NewDedupWriter(rw RecordWriter) RecordWriter
NewDedupWriter returns a new deduplicating rw.