Documentation ¶
Overview ¶
Package lz supports encoding and decoding of LZ77 sequences. A sequence, as described in the Zstandard specification, consists of a literal copy command followed by a match copy command. The literal copy command is described by the length in literal bytes to be copied and the match command consists of the distance of the match to copy and the length of the match in bytes.
A Parser is an encoder that converts a byte stream into blocks of sequences. A Decoder converts the block of sequences into the original decompressed byte stream.
The actual basic Parser provided by the package support the SeqBuffer interface, which has methods for writing and reading from the buffer. A pure Parser is provided by the [Wrap function.
The module provides multiple parser implementations that provide different combinations of encoding speed and compression ratios. Usually a slower parser will generate a better compression ratio.
The Decoder slides the decompression window through a larger buffer implemented by [DecBuffer].
The library supports the implementation of Parsers outside the package that can then be used by real compressors as provided by the github.com/ulikunitz/xz module.
Index ¶
- Constants
- Variables
- func XZCost(m, o uint32) uint64
- type BDHPConfig
- func (cfg *BDHPConfig) BufConfig() BufConfig
- func (cfg *BDHPConfig) Clone() ParserConfig
- func (cfg *BDHPConfig) MarshalJSON() (p []byte, err error)
- func (cfg BDHPConfig) NewParser() (s Parser, err error)
- func (cfg *BDHPConfig) SetBufConfig(bc BufConfig)
- func (cfg *BDHPConfig) SetDefaults()
- func (cfg *BDHPConfig) UnmarshalJSON(p []byte) error
- func (cfg *BDHPConfig) Verify() error
- type BHPConfig
- func (cfg *BHPConfig) BufConfig() BufConfig
- func (cfg *BHPConfig) Clone() ParserConfig
- func (cfg *BHPConfig) MarshalJSON() (p []byte, err error)
- func (cfg BHPConfig) NewParser() (s Parser, err error)
- func (cfg *BHPConfig) SetBufConfig(bc BufConfig)
- func (cfg *BHPConfig) SetDefaults()
- func (cfg *BHPConfig) UnmarshalJSON(p []byte) error
- func (cfg *BHPConfig) Verify() error
- type BUPConfig
- func (cfg *BUPConfig) BufConfig() BufConfig
- func (cfg *BUPConfig) Clone() ParserConfig
- func (cfg *BUPConfig) MarshalJSON() (p []byte, err error)
- func (cfg BUPConfig) NewParser() (s Parser, err error)
- func (cfg *BUPConfig) SetBufConfig(bc BufConfig)
- func (cfg *BUPConfig) SetDefaults()
- func (cfg *BUPConfig) UnmarshalJSON(p []byte) error
- func (cfg *BUPConfig) Verify() error
- type Block
- type BufConfig
- type DHPConfig
- func (cfg *DHPConfig) BufConfig() BufConfig
- func (cfg *DHPConfig) Clone() ParserConfig
- func (cfg *DHPConfig) MarshalJSON() (p []byte, err error)
- func (cfg DHPConfig) NewParser() (s Parser, err error)
- func (cfg *DHPConfig) SetBufConfig(bc BufConfig)
- func (cfg *DHPConfig) SetDefaults()
- func (cfg *DHPConfig) UnmarshalJSON(p []byte) error
- func (cfg *DHPConfig) Verify() error
- type Decoder
- type DecoderBuffer
- func (b *DecoderBuffer) ByteAtEnd(off int) byte
- func (b *DecoderBuffer) Init(cfg DecoderConfig) error
- func (b *DecoderBuffer) Read(p []byte) (n int, err error)
- func (b *DecoderBuffer) Reset()
- func (b *DecoderBuffer) Write(p []byte) (n int, err error)
- func (b *DecoderBuffer) WriteBlock(blk Block) (n, k, l int, err error)
- func (b *DecoderBuffer) WriteByte(c byte) error
- func (b *DecoderBuffer) WriteMatch(m, o uint32) (n int, err error)
- func (b *DecoderBuffer) WriteTo(w io.Writer) (n int64, err error)
- type DecoderConfig
- type GSAPConfig
- func (cfg *GSAPConfig) BufConfig() BufConfig
- func (cfg *GSAPConfig) Clone() ParserConfig
- func (cfg *GSAPConfig) MarshalJSON() (p []byte, err error)
- func (cfg GSAPConfig) NewParser() (s Parser, err error)
- func (cfg *GSAPConfig) SetBufConfig(bc BufConfig)
- func (cfg *GSAPConfig) SetDefaults()
- func (cfg *GSAPConfig) UnmarshalJSON(p []byte) error
- func (cfg *GSAPConfig) Verify() error
- type HPConfig
- func (cfg *HPConfig) BufConfig() BufConfig
- func (cfg *HPConfig) Clone() ParserConfig
- func (cfg *HPConfig) MarshalJSON() (p []byte, err error)
- func (cfg HPConfig) NewParser() (s Parser, err error)
- func (cfg *HPConfig) SetBufConfig(bc BufConfig)
- func (cfg *HPConfig) SetDefaults()
- func (cfg *HPConfig) UnmarshalJSON(p []byte) error
- func (cfg *HPConfig) Verify() error
- type OSAPConfig
- func (cfg *OSAPConfig) BufConfig() BufConfig
- func (cfg *OSAPConfig) Clone() ParserConfig
- func (cfg *OSAPConfig) MarshalJSON() (p []byte, err error)
- func (cfg *OSAPConfig) NewParser() (s Parser, err error)
- func (cfg *OSAPConfig) SetBufConfig(bc BufConfig)
- func (cfg *OSAPConfig) SetDefaults()
- func (cfg *OSAPConfig) UnmarshalJSON(p []byte) error
- func (cfg *OSAPConfig) Verify() error
- type Parser
- type ParserBuffer
- func (b *ParserBuffer) ByteAt(off int64) (c byte, err error)
- func (b *ParserBuffer) Init(cfg BufConfig) error
- func (b *ParserBuffer) PeekAt(n int, off int64) (p []byte, err error)
- func (b *ParserBuffer) ReadAt(p []byte, off int64) (n int, err error)
- func (b *ParserBuffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *ParserBuffer) Reset(data []byte) error
- func (b *ParserBuffer) Shrink() int
- func (b *ParserBuffer) Write(p []byte) (n int, err error)
- type ParserConfig
- type Seq
- type WrappedParser
Constants ¶
const ( // NoTrailingLiterals tells a parser that trailing literals don't // need to be included in the block. NoTrailingLiterals = 1 << iota )
Flags for the sequence function stored in the block structure.
Variables ¶
var ( ErrOutOfBuffer = errors.New("lz: offset outside of buffer") ErrEndOfBuffer = errors.New("lz: end of buffer") )
Errors returned by [SeqBuffer.ReadAt]
var ErrEmptyBuffer = errors.New("lz: no more data in buffer")
ErrEmptyBuffer indicates that no more data is available in the buffer. It will be returned by the Parse method of Parser.
var ErrFullBuffer = errors.New("lz: buffer is full")
ErrFullBuffer indicates that the buffer is full. It will be returned by the Write and ReadFrom methods of the Parser.
Functions ¶
Types ¶
type BDHPConfig ¶ added in v0.3.0
type BDHPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int InputLen1 int HashBits1 int InputLen2 int HashBits2 int }
BDHPConfig provides the configuration parameters for the Backward-looking Double Hash Parser.
func (*BDHPConfig) BufConfig ¶ added in v0.3.0
func (cfg *BDHPConfig) BufConfig() BufConfig
BufConfig returns the BufConfig value containing the buffer parameters.
func (*BDHPConfig) Clone ¶ added in v0.3.1
func (cfg *BDHPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*BDHPConfig) MarshalJSON ¶ added in v0.3.0
func (cfg *BDHPConfig) MarshalJSON() (p []byte, err error)
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "BDHP" to the structure.
func (BDHPConfig) NewParser ¶ added in v0.3.0
func (cfg BDHPConfig) NewParser() (s Parser, err error)
NewParser creates a new DoubleHashParser.
func (*BDHPConfig) SetBufConfig ¶ added in v0.3.0
func (cfg *BDHPConfig) SetBufConfig(bc BufConfig)
SetBufConfig sets the buffer configuration.
func (*BDHPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *BDHPConfig) SetDefaults()
SetDefaults uses the defaults for the configuration parameters that are set to zero.
func (*BDHPConfig) UnmarshalJSON ¶ added in v0.3.0
func (cfg *BDHPConfig) UnmarshalJSON(p []byte) error
UnmarshalJSON parses the JSON value and sets the fields of BDHPConfig.
func (*BDHPConfig) Verify ¶ added in v0.3.0
func (cfg *BDHPConfig) Verify() error
Verify checks the configuration for errors.
type BHPConfig ¶ added in v0.3.0
type BHPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int InputLen int HashBits int }
BHPConfig provides the parameters for the backward hash parser.
func (*BHPConfig) BufConfig ¶ added in v0.3.0
BufConfig returns the BufConfig value containing the buffer parameters.
func (*BHPConfig) Clone ¶ added in v0.3.1
func (cfg *BHPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*BHPConfig) MarshalJSON ¶ added in v0.3.0
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "BHP" to the structure.
func (*BHPConfig) SetBufConfig ¶ added in v0.3.0
SetBufConfig sets the buffer configuration parameters of the backward hash parser configuration.
func (*BHPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *BHPConfig) SetDefaults()
SetDefaults sets values that are zero to their defaults values.
func (*BHPConfig) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON parses the JSON value and sets the fields of BHPConfig.
type BUPConfig ¶ added in v0.3.0
type BUPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int InputLen int HashBits int BucketSize int }
BUPConfig provides the configuration parameters for the bucket hash parser.
func (*BUPConfig) BufConfig ¶ added in v0.3.0
BufConfig returns the BufConfig value containing the buffer parameters.
func (*BUPConfig) Clone ¶ added in v0.3.1
func (cfg *BUPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*BUPConfig) MarshalJSON ¶ added in v0.3.0
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "BUP" to the structure.
func (*BUPConfig) SetBufConfig ¶ added in v0.3.0
SetBufConfig sets the buffer configuration parameters of the parser configuration.
func (*BUPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *BUPConfig) SetDefaults()
SetDefaults sets values that are zero to their defaults values.
func (*BUPConfig) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON parses the JSON value and sets the fields of BUPConfig.
type Block ¶
Block stores sequences and literals. Note that the sequences stores in the Sequences slice might not consume the whole Literals slice. They must be added to the decoded text after all the sequences have been decoded and their content added to the decoder buffer.
type BufConfig ¶ added in v0.2.0
BufConfig describes the various sizes relevant for the buffer. Note that ShrinkSize should be significantly smaller than BufferSize and at most 50% of it. The WindowSize is independent of the BufferSize, but usually the BufferSize should be larger or equal the WindowSize. The actual sequencing happens in blocks. A typical BlockSize 128 kByte as used by ZStandard specification.
func (*BufConfig) BufferConfig ¶ added in v0.2.0
BufferConfig returns itself, which will be used by the structures embedding the value.
func (*BufConfig) SetDefaults ¶ added in v0.2.1
func (cfg *BufConfig) SetDefaults()
SetDefaults sets the defaults for the various size values. The defaults are given below.
BufferSize: 8 MiB ShrinkSize: 32 KiB (or half of BufferSize, if it is smaller than 64 KiB) WindowSize: BufferSize BlockSize: 128 KiB
type DHPConfig ¶ added in v0.3.0
type DHPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int InputLen1 int HashBits1 int InputLen2 int HashBits2 int }
DHPConfig provides the configuration parameters for the DoubleHashParser.
func (*DHPConfig) BufConfig ¶ added in v0.3.0
BufConfig returns the BufConfig value containing the buffer parameters.
func (*DHPConfig) Clone ¶ added in v0.3.1
func (cfg *DHPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*DHPConfig) MarshalJSON ¶ added in v0.3.0
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "DHP" to the structure.
func (*DHPConfig) SetBufConfig ¶ added in v0.3.0
SetBufConfig sets the buffer configuration parameters of the parser configuration.
func (*DHPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *DHPConfig) SetDefaults()
SetDefaults uses the defaults for the configuration parameters that are set to zero.
func (*DHPConfig) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON parses the JSON value and sets the fields of DHPConfig.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes LZ77 sequences and writes them into the writer.
func NewDecoder ¶
func NewDecoder(w io.Writer, cfg DecoderConfig) (*Decoder, error)
NewDecoder creates a new decoder. The first issue with the configuration will be reported.
func (*Decoder) Init ¶
func (d *Decoder) Init(w io.Writer, cfg DecoderConfig) error
Init initializes the decoder. The first issue of the configuration value will be reported as error.
func (*Decoder) WriteBlock ¶
WriteBlock writes the block into the decoder. It returns the number n of bytes, the number k of parsers and the number l of literal bytes written to the decoder.
type DecoderBuffer ¶ added in v0.3.0
type DecoderBuffer struct { // Data is the actual buffer. The end of the slice is also the head of // the dictionary window. Data []byte // R tracks the position of the reads from the buffer and must be less // or equal the length of the Data slice. R int // Off records the total offset and marks the end of the Data slice, // which is also the end of the dictionary window. Off int64 // DecConfig provides the configuration parameters WindowSize and // BufferSize. DecoderConfig }
DecoderBuffer provides a simple buffer for the decoding of LZ77 sequences.
func (*DecoderBuffer) ByteAtEnd ¶ added in v0.3.0
func (b *DecoderBuffer) ByteAtEnd(off int) byte
ByteAtEnd returns byte at end of the buffer
func (*DecoderBuffer) Init ¶ added in v0.3.0
func (b *DecoderBuffer) Init(cfg DecoderConfig) error
Init initializes the [DecBuffer] value.
func (*DecoderBuffer) Read ¶ added in v0.3.0
func (b *DecoderBuffer) Read(p []byte) (n int, err error)
Read reads decoded data from the buffer.
func (*DecoderBuffer) Reset ¶ added in v0.3.0
func (b *DecoderBuffer) Reset()
Reset puts the DecBuffer back to the initialized status.
func (*DecoderBuffer) Write ¶ added in v0.3.0
func (b *DecoderBuffer) Write(p []byte) (n int, err error)
Write puts the slice into the buffer. The method will write the slice only fully or will return 0, ErrFullBuffer.
func (*DecoderBuffer) WriteBlock ¶ added in v0.3.0
func (b *DecoderBuffer) WriteBlock(blk Block) (n, k, l int, err error)
WriteBlock writes sequences from the block into the buffer. A single sequence will be written in an atomic manner, because the block value will not be modified. If there is not enough space in the buffer ErrFullBuffer will be returned.
We are not limiting the growth of the array to BufferSize. We may consume more memory but we are faster.
The return values n, k and l provide the number of bytes written into the buffer, the number of sequences as well as the number of literals.
func (*DecoderBuffer) WriteByte ¶ added in v0.3.0
func (b *DecoderBuffer) WriteByte(c byte) error
WriteByte writes a single byte into the buffer.
func (*DecoderBuffer) WriteMatch ¶ added in v0.3.0
func (b *DecoderBuffer) WriteMatch(m, o uint32) (n int, err error)
WriteMatch puts the match at the end of the buffer. The match will only be written completely or n=0 and ErrFullBuffer will be returned.
type DecoderConfig ¶ added in v0.3.0
type DecoderConfig struct { // Size of the sliding dictionary window in bytes. WindowSize int // Maximum size of the buffer in bytes. BufferSize int }
DecoderConfig contains the parameters for the [DecBuffer] and Decoder types. The WindowSize must be smaller than the BufferSize. It is recommended to set the BufferSize twice as large as the WindowSize.
func (*DecoderConfig) SetDefaults ¶ added in v0.3.0
func (cfg *DecoderConfig) SetDefaults()
SetDefaults sets the zero values in DecConfig to default values. Note that the default BufferSize is twice the WindowSize.
func (*DecoderConfig) Verify ¶ added in v0.3.0
func (cfg *DecoderConfig) Verify() error
Verify checks the parameters of the [DecConfig] value and returns an error for the first problem.
type GSAPConfig ¶ added in v0.3.0
type GSAPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int // minimum match len MinMatchLen int }
GSAPConfig defines the configuration parameter for the greedy suffix array parser.
func (*GSAPConfig) BufConfig ¶ added in v0.3.0
func (cfg *GSAPConfig) BufConfig() BufConfig
BufConfig returns the BufConfig value containing the buffer parameters.
func (*GSAPConfig) Clone ¶ added in v0.3.1
func (cfg *GSAPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*GSAPConfig) MarshalJSON ¶ added in v0.3.0
func (cfg *GSAPConfig) MarshalJSON() (p []byte, err error)
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "GSAP" to the structure.
func (GSAPConfig) NewParser ¶ added in v0.3.0
func (cfg GSAPConfig) NewParser() (s Parser, err error)
NewParser generates a new parser using the configuration parameters in the structure.
func (*GSAPConfig) SetBufConfig ¶ added in v0.3.0
func (cfg *GSAPConfig) SetBufConfig(bc BufConfig)
SetBufConfig sets the buffer configuration parameters of the parser configuration.
func (*GSAPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *GSAPConfig) SetDefaults()
SetDefaults sets configuration parameters to its defaults. The code doesn't provide consistency.
func (*GSAPConfig) UnmarshalJSON ¶ added in v0.3.0
func (cfg *GSAPConfig) UnmarshalJSON(p []byte) error
UnmarshalJSON parses the JSON value and sets the fields of GSAPConfig.
func (*GSAPConfig) Verify ¶ added in v0.3.0
func (cfg *GSAPConfig) Verify() error
Verify checks the configuration for inconsistencies.
type HPConfig ¶ added in v0.3.0
type HPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int InputLen int HashBits int }
HPConfig provides the configuration parameters for the HashParser. Parser doesn't use ShrinkSize and and BufferSize itself, but it provides it to other code that have to handle the buffer.
func (*HPConfig) BufConfig ¶ added in v0.3.0
BufConfig returns the BufConfig value containing the buffer parameters.
func (*HPConfig) Clone ¶ added in v0.3.1
func (cfg *HPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*HPConfig) MarshalJSON ¶ added in v0.3.0
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "HP" to the structure.
func (*HPConfig) SetBufConfig ¶ added in v0.3.0
SetBufConfig sets the buffer configuration parameters of the parser configuration.
func (*HPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *HPConfig) SetDefaults()
SetDefaults sets values that are zero to their defaults values.
func (*HPConfig) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON converts the JSON into the HPConfig structure.
type OSAPConfig ¶ added in v0.3.0
type OSAPConfig struct { ShrinkSize int BufferSize int WindowSize int BlockSize int MinMatchLen int MaxMatchLen int Cost string }
OSAPConfig provides the configuration parameters for the Optimizing Suffix Array Parser (OSAP).
func (*OSAPConfig) BufConfig ¶ added in v0.3.0
func (cfg *OSAPConfig) BufConfig() BufConfig
BufConfig returns the BufConfig value for the OSAP configuration.
func (*OSAPConfig) Clone ¶ added in v0.3.1
func (cfg *OSAPConfig) Clone() ParserConfig
Clone creates a copy of the configuration.
func (*OSAPConfig) MarshalJSON ¶ added in v0.3.0
func (cfg *OSAPConfig) MarshalJSON() (p []byte, err error)
MarshalJSON creates the JSON string for the configuration. Note that it adds a property Type with value "OSAP" to the structure.
func (*OSAPConfig) NewParser ¶ added in v0.3.0
func (cfg *OSAPConfig) NewParser() (s Parser, err error)
NewParser returns the Optimizing Parser Array Parser.
func (*OSAPConfig) SetBufConfig ¶ added in v0.3.0
func (cfg *OSAPConfig) SetBufConfig(bc BufConfig)
SetBufConfig sets the buffer configuration parameters of the parser configuration.
func (*OSAPConfig) SetDefaults ¶ added in v0.3.0
func (cfg *OSAPConfig) SetDefaults()
SetDefaults sets the defaults for the zero values of the the OSAP configuration.
func (*OSAPConfig) UnmarshalJSON ¶ added in v0.3.0
func (cfg *OSAPConfig) UnmarshalJSON(p []byte) error
UnmarshalJSON parses the JSON value and sets the fields of OSAPConfig.
func (*OSAPConfig) Verify ¶ added in v0.3.0
func (cfg *OSAPConfig) Verify() error
Verify verifies the configuration for the Optimizing Suffix Array Parser.
type Parser ¶ added in v0.3.0
type Parser interface { Parse(blk *Block, flags int) (n int, err error) Reset(data []byte) error Shrink() int ParserConfig() ParserConfig BufferConfig() BufConfig Write(p []byte) (n int, err error) ReadFrom(r io.Reader) (n int64, err error) ReadAt(p []byte, off int64) (n int, err error) ByteAt(off int64) (c byte, err error) }
Parser provides the basic interface of a Parser. It provides the functions provided by SeqBuffer.
type ParserBuffer ¶ added in v0.3.0
type ParserBuffer struct { // actual buffer data Data []byte // w position of the head of the window in data. W int // off start of the data slice, counts all data written and discarded // from the buffer. Off int64 BufConfig }
ParserBuffer provides a base for Parser implementation. Since the package allows implementations outside of the package. All members are public.
func (*ParserBuffer) ByteAt ¶ added in v0.3.0
func (b *ParserBuffer) ByteAt(off int64) (c byte, err error)
ByteAt returns the byte at total offset off, if it can be provided. If off points to the end of the buffer, ErrEndOfBuffer will be returned otherwise ErrOutOfBuffer.
func (*ParserBuffer) Init ¶ added in v0.3.0
func (b *ParserBuffer) Init(cfg BufConfig) error
Init initializes the buffer. The function sets the defaults for the buffer configuration if required and verifies it. Errors will be reported.
func (*ParserBuffer) PeekAt ¶ added in v0.3.0
func (b *ParserBuffer) PeekAt(n int, off int64) (p []byte, err error)
PeekAt returns part of the internal data slice starting at total offset off. The total offset takes all data written to the buffer into account. If the off parameter is outside the current buffer ErrOutOfBuffer will be returned. If less than n bytes of data can be provided ErrEndOfBuffer will be returned.
func (*ParserBuffer) ReadAt ¶ added in v0.3.0
func (b *ParserBuffer) ReadAt(p []byte, off int64) (n int, err error)
ReadAt reads data from the buffer at position off. If off is is outside the buffer ErrOutOfBuffer will be reported. If there is not enough data to fill p ErrEndOfBuffer will be reported. See [SeqBuffer.PeekAt] for avoiding the copy.
func (*ParserBuffer) ReadFrom ¶ added in v0.3.0
func (b *ParserBuffer) ReadFrom(r io.Reader) (n int64, err error)
ReadFrom reads the data from reader into the buffer. If there is an error it will be reported. If the buffer is full, ErrFullBuffer will be reported.
func (*ParserBuffer) Reset ¶ added in v0.3.0
func (b *ParserBuffer) Reset(data []byte) error
Reset initializes the buffer with new data. The data slice requires a margin of 7 bytes for the hash parsers to be used directly. If there is no margin the data will be copied into a slice with enough capacity.
func (*ParserBuffer) Shrink ¶ added in v0.3.0
func (b *ParserBuffer) Shrink() int
Shrink will move the window head to the shrink size if it is larger. The amount of data discarded from the buffer, named delta, will be returned.
func (*ParserBuffer) Write ¶ added in v0.3.0
func (b *ParserBuffer) Write(p []byte) (n int, err error)
Write writes data into the buffer. If not the complete p slice can be copied into the buffer, Write will return ErrFullBuffer.
type ParserConfig ¶ added in v0.3.0
type ParserConfig interface { NewParser() (s Parser, err error) BufConfig() BufConfig SetBufConfig(bc BufConfig) SetDefaults() Verify() error Clone() ParserConfig }
ParserConfig generates new parser instances. Note that the parser doesn't use ShrinkSize and BufferSize directly but we added it here, so it can be used for the WriteParser which provides a WriteCloser interface.
func ParseJSON ¶ added in v0.2.1
func ParseJSON(p []byte) (s ParserConfig, err error)
ParseJSON parses a JSON structure
type Seq ¶
Seq represents a single Lempel-Ziv 77 Parse describing a match, consisting of the offset, the length of the match and the number of literals preceding the match. The Aux field can be used on upper layers to store additional information.
type WrappedParser ¶ added in v0.3.0
type WrappedParser struct {
// contains filtered or unexported fields
}
WrappedParser is returned by the Wrap function. It provides the Parse method and reads the data required automatically from the stored reader.
func Wrap ¶
func Wrap(r io.Reader, seq Parser) *WrappedParser
Wrap combines a reader and a Parser and makes a Parser. The user doesn't need to take care of filling the Parser with additional data. The returned parser returns EOF if no further data is available.
Wrap chooses the minimum of 32 kbyte or half of the window size as shrink size.
func (*WrappedParser) Parse ¶ added in v0.3.0
func (s *WrappedParser) Parse(blk *Block, flags int) (n int, err error)
Parse creates a block of sequences but reads the required data from the reader if necessary. The function returns io.EOF if no further data is available.
func (*WrappedParser) Reset ¶ added in v0.3.0
func (s *WrappedParser) Reset(r io.Reader)
Reset puts the WrappedParser in its initial state and changes the wrapped reader to another reader.