objfile

package
Version: v3.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	// ErrOverflow is returned when an attempt is made to write more data than
	// was declared in NewWriter.
	ErrOverflow = errors.New("objfile: declared data length exceeded (overflow)")
)
View Source
var (
	// ErrZLib is returned when the objfile contains invalid zlib data.
	ErrZLib = errors.New("objfile: invalid zlib data")
)

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

func NewReader(r io.Reader) (*Reader, error)

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

func (r *Reader) Close() (err error)

Close releases any resources consumed by the Reader.

Calling Close does not close the wrapped io.Reader originally passed to NewReader.

func (*Reader) Hash

func (r *Reader) Hash() core.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

func (r *Reader) Read(p []byte) (n int, err error)

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

func (r *Reader) Size() int64

Size returns the uncompressed size of the object in bytes.

func (*Reader) Type

func (r *Reader) Type() core.ObjectType

Type returns the type of the object.

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

func NewWriter(w io.Writer, t core.ObjectType, size int64) (*Writer, error)

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

func (w *Writer) Close() (err error)

Close releases any resources consumed by the Writer.

Calling Close does not close the wrapped io.Writer originally passed to NewWriter.

func (*Writer) Hash

func (w *Writer) Hash() core.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

func (w *Writer) Size() int64

Size returns the uncompressed size of the object in bytes.

func (*Writer) Type

func (w *Writer) Type() core.ObjectType

Type returns the type of the object.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL