Documentation ¶
Overview ¶
Package kzip implements the kzip compilation storage file format.
The package exports two types of interest: A kzip.Reader can be used to read the contents of an existing kzip archive, and a kzip.Writer can be used to construct a new kzip archive.
Reading an Archive:
r, err := kzip.NewReader(file, size) ... // Look up a compilation record by its digest. unit, err := r.Lookup(unitDigest) ... // Scan all the compilation records stored. err := r.Scan(func(unit *kzip.Unit) error { if hasInterestingProperty(unit) { doStuffWith(unit) } return nil }) // Open a reader for a stored file. rc, err := r.Open(fileDigest) ... defer rc.Close() // Read the complete contents of a stored file. bits, err := r.ReadAll(fileDigest) ...
Writing an Archive:
w, err := kzip.NewWriter(file) ... // Add a compilation record and (optional) index data. udigest, err := w.AddUnit(unit, nil) ... // Add file contents. fdigest, err := w.AddFile(file) ...
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDigestNotFound = errors.New("digest not found")
ErrDigestNotFound is returned when a requested compilation unit or file digest is not found.
var ErrUnitExists = errors.New("unit already exists")
ErrUnitExists is returned by AddUnit when adding the same compilation multiple times.
Functions ¶
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader permits reading and scanning compilation records and file contents stored in a .kzip archive. The Lookup and Scan methods are mutually safe for concurrent use by multiple goroutines.
func NewReader ¶
NewReader constructs a new Reader that consumes zip data from r, whose total size in bytes is given.
func (*Reader) Lookup ¶
Lookup returns the specified compilation from the archive, if it exists. If the requested digest is not in the archive, ErrDigestNotFound is returned.
func (*Reader) Open ¶
func (r *Reader) Open(fileDigest string) (io.ReadCloser, error)
Open opens a reader on the contents of the specified file digest. If the requested digest is not in the archive, ErrDigestNotFound is returned. The caller must close the reader when it is no longer needed.
type Unit ¶
type Unit struct { Digest string Proto *apb.CompilationUnit Index *apb.IndexedCompilation_Index }
A Unit represents a compilation record read from a kzip archive.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer permits construction of a .kzip archive.
func NewWriteCloser ¶ added in v0.0.28
func NewWriteCloser(wc io.WriteCloser) (*Writer, error)
NewWriteCloser behaves as NewWriter, but arranges that when the *Writer is closed it also closes wc.
func NewWriter ¶
NewWriter constructs a new empty Writer that delivers output to w. The AddUnit and AddFile methods are safe for use by concurrent goroutines.
func (*Writer) AddFile ¶
AddFile copies the complete contents of r into the archive as a new file entry, returning the hex-encoded SHA256 digest of the file's contents.
func (*Writer) AddUnit ¶
func (w *Writer) AddUnit(cu *apb.CompilationUnit, index *apb.IndexedCompilation_Index) (string, error)
AddUnit adds a new compilation record to be added to the archive, returning the hex-encoded SHA256 digest of the unit's contents. It is legal for index to be nil, in which case no index terms will be added.
If the same compilation is added multiple times, AddUnit returns the digest of the duplicated compilation along with ErrUnitExists to all callers after the first. The existing unit is not modified.