Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTruncatedData is returned when attempting to read data from a buffer // or reader with insufficient data. ErrTruncatedData = errors.New("insufficient or truncated data") // ErrInvalidHeader is returned when attempting to decode a data run // header that has an invalid size. ErrInvalidHeader = errors.New("invalid data run header") )
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes data in an underlying reader as a serires of data run mapping pairs.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r until it encounters an end-of-stream header.
func (*Decoder) Read ¶
func (d *Decoder) Read() (MappingPair, error)
Read returns the next mapping pair from d. It returns io.EOF when there is no more data to return.
type Header ¶
type Header byte
Header describes the allocation of bytes in a mapping pair.
const EOF Header = 0
EOF is a sentinel header value indicating the end of a series of mapping pairs.
It is not to be confused with io.EOF, which is a sentinel error value.
func (Header) DataBytes ¶
DataBytes returns the number of data bytes in a mapping pair, excluding the header itself.
func (Header) LengthBytes ¶
LengthBytes returns the number of length bytes in a mapping pair.
func (Header) OffsetBytes ¶
OffsetBytes returns the number of offset bytes in a mapping pair.
type MappingPair ¶
type MappingPair struct { Length uint64 // In clusters Offset int64 // Relative to previous data run, may be negative }
MappingPair stores the length and offset of a logical cluster number so that it can be mapped to a virtual cluster number.
func Decode ¶
func Decode(data []byte) (pairs []MappingPair, err error)
Decode decodes data until it encounters EOF in the data stream or encounters an error. It returns a slice of all the mapping pairs it decoded. If the data is decoded successfully err will be nil.