Documentation
¶
Overview ¶
Package lzss implements LZSS:8bit compression and decompression.
Format: one flag byte per 8 slots; bit 1 = literal (1 byte), bit 0 = pointer (2 bytes). Pointer: 12-bit backward offset from current output position, 4-bit length → (len&0x0F)+3 (3..18 bytes). Sliding window: 4096 bytes; filler 0x20 when offset refers before start of output. Trailing 4-byte checksum: either unsigned (sum of bytes as uint8) or signed (sum as int8).
Use Decompress(src, outLen, opts) with nil for default (unsigned, strict checksum). Use SignedLenientOptions() for formats that use signed checksum and ignore mismatch.
Index ¶
Constants ¶
const ( WindowSize = 4096 // Sliding window size (ring buffer). MaxMatch = 18 // Maximum back-reference length (encoded as 3..18). Filler = 0x20 // Fill byte when back-reference offset is before start of output. FlagBits = 8 // Bits per flag byte (one flag byte per 8 slots: literal or pointer). )
LZSS:8bit format constants.
Variables ¶
var ( ErrInputTooShort = errors.New("not enough data for checksum") ErrUnexpectedEOF = errors.New("unexpected end of input while reading flags") ErrUnexpectedEOFBit = errors.New("unexpected end of input inside flags block") ErrEmptyInput = errors.New("input is empty") )
Package errors. Use errors.New for static messages, fmt.Errorf when values are needed.
Functions ¶
Types ¶
type ChecksumMode ¶
type ChecksumMode int
ChecksumMode defines how the 4-byte checksum is computed.
const ( ChecksumUnsigned ChecksumMode = iota // Sum bytes as uint8 (default for archives). ChecksumSigned // Sum bytes as int8 (used by some texture formats). )
Checksum mode constants.
type CompressOptions ¶
type CompressOptions struct {
Checksum ChecksumMode
SearchLimit int // 0 = literals only; otherwise max backward distance for match search (e.g. 64..4096).
}
CompressOptions configures compression (checksum mode and search limit).
func DefaultCompressOptions ¶
func DefaultCompressOptions() *CompressOptions
DefaultCompressOptions returns options for default compression (unsigned checksum, search limit 2048).
type Options ¶
type Options struct {
// Checksum sets unsigned vs signed checksum.
Checksum ChecksumMode
// VerifyChecksum: if true, Decompress returns an error on checksum mismatch.
// If false, mismatch is ignored (lenient mode for formats with often-bad checksums).
VerifyChecksum bool
}
Options configures Decompress and Compress behavior.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns options for default behavior: unsigned checksum, strict verification.
func SignedLenientOptions ¶
func SignedLenientOptions() *Options
SignedLenientOptions returns options: signed checksum, do not return error on mismatch.