Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned when the objfile Reader or Writer is already closed. ErrClosed = errors.New("objfile: already closed") // ErrHeader is returned when the objfile has an invalid header. ErrHeader = errors.New("objfile: invalid header") // ErrNegativeSize is returned when a negative object size is declared. ErrNegativeSize = errors.New("objfile: negative object size") )
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads and decodes compressed objfile data from a provided io.Reader.
Reader implements io.ReadCloser. Close should be called when finished with the Reader. Close will not close the underlying io.Reader.
func NewReader ¶
NewReader returns a new Reader reading from r.
Calling NewReader causes it to immediately read in header data from r containing size and type information. Any errors encountered in that process will be returned in err.
The returned Reader implements io.ReadCloser. Close should be called when finished with the Reader. Close will not close the underlying io.Reader.
func (*Reader) Close ¶
Close releases any resources consumed by the Reader.
Calling Close does not close the wrapped io.Reader originally passed to NewReader.
func (*Reader) Hash ¶
Hash returns the hash of the object data stream that has been read so far. It can be called before or after Close.
func (*Reader) Read ¶
Read reads len(p) bytes into p from the object data stream. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if Read returns n < len(p), it may use all of p as scratch space during the call.
If Read encounters the end of the data stream it will return err == io.EOF, either in the current call if n > 0 or in a subsequent call.
func (*Reader) Size ¶
Size returns the uncompressed size of the object in bytes.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes and encodes data in compressed objfile format to a provided io.Writer.
Writer implements io.WriteCloser. Close should be called when finished with the Writer. Close will not close the underlying io.Writer.
func NewWriter ¶
NewWriter returns a new Writer writing to w.
The provided t is the type of object being written. The provided size is the number of uncompressed bytes being written.
Calling NewWriter causes it to immediately write header data containing size and type information. Any errors encountered in that process will be returned in err.
If an invalid t is provided, core.ErrInvalidType is returned. If a negative size is provided, ErrNegativeSize is returned.
The returned Writer implements io.WriteCloser. Close should be called when finished with the Writer. Close will not close the underlying io.Writer.
func (*Writer) Close ¶
Close releases any resources consumed by the Writer.
Calling Close does not close the wrapped io.Writer originally passed to NewWriter.
func (*Writer) Hash ¶
Hash returns the hash of the object data stream that has been written so far. It can be called before or after Close.
func (*Writer) Size ¶
Size returns the uncompressed size of the object in bytes.
func (*Writer) Write ¶
Write reads len(p) from p to the object data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. The slice data contained in p will not be modified.
If writing len(p) bytes would exceed the size provided in NewWriter, ErrOverflow is returned without writing any data.