lzss

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MaxInputSize = 1 << 22 // 4Mb
	MaxDictSize  = 1 << 22 // 4Mb
)
View Source
const (
	SymbolDynamic byte = 0xFF
	SymbolShort   byte = 0xFE
)
View Source
const (
	// Version is the current release version of the compressor.
	Version    = 1
	HeaderSize = 3
)

Variables

This section is empty.

Functions

func AugmentDict

func AugmentDict(dict []byte) []byte

AugmentDict ensures the dictionary contains the special symbols

func Decompress

func Decompress(data, dict []byte) (d []byte, err error)

Decompress decompresses the given data using the given dictionary the dictionary must be the same as the one used to compress the data Note that this is not a fail-safe decompressor, it will fail ungracefully if the data has a different format than the one expected

Types

type BackrefType

type BackrefType struct {
	Delimiter     byte
	NbBitsAddress uint8
	NbBitsLength  uint8
	NbBitsBackRef uint8

	DictLen int
	// contains filtered or unexported fields
}

func NewDynamicBackrefType

func NewDynamicBackrefType(dictLen, addressableBytes int) (dynamic BackrefType)

func NewShortBackrefType

func NewShortBackrefType() (short BackrefType)

type CompressionPhrase

type CompressionPhrase struct {
	Type              byte
	Length            int
	ReferenceAddress  int
	StartDecompressed int
	StartCompressed   int
	Content           []byte
}

type CompressionPhrases

type CompressionPhrases []CompressionPhrase

func CompressedStreamInfo

func CompressedStreamInfo(c, dict []byte) (CompressionPhrases, error)

func (CompressionPhrases) ToCSV

func (c CompressionPhrases) ToCSV() []byte

type Compressor

type Compressor struct {
	// contains filtered or unexported fields
}

func NewCompressor

func NewCompressor(dict []byte) (*Compressor, error)

NewCompressor returns a new compressor with the given dictionary The dictionary is an unstructured sequence of substrings that are expected to occur frequently in the data. It is not included in the compressed data and should thus be a-priori known to both the compressor and the decompressor. The level determines the bit alignment of the compressed data. The "higher" the level, the better the compression ratio but the more constraints on the decompressor.

func (*Compressor) Bytes

func (compressor *Compressor) Bytes() []byte

Bytes returns the compressed data

func (*Compressor) Compress

func (compressor *Compressor) Compress(d []byte) (c []byte, err error)

Compress compresses the given data and returns the compressed data

func (*Compressor) CompressedSize256k

func (compressor *Compressor) CompressedSize256k(d []byte) (size int, err error)

CompressedSize256k returns the size of the compressed data This is state less and thread-safe (but other methods are not) Max size of d is 256kB

func (*Compressor) ConsiderBypassing

func (compressor *Compressor) ConsiderBypassing() (bypassed bool)

ConsiderBypassing switches to NoCompression if we get significant expansion instead of compression

func (*Compressor) Len

func (compressor *Compressor) Len() int

Len returns the number of bytes compressed so far (includes the header)

func (*Compressor) Reset

func (compressor *Compressor) Reset()

func (*Compressor) Revert

func (compressor *Compressor) Revert() error

Revert undoes the last call to Write between any two calls to Revert, a call to Reset or Write should be made

func (*Compressor) Write

func (compressor *Compressor) Write(d []byte) (n int, err error)

The compressor cannot recover from a Write error. It must be Reset before writing again

func (*Compressor) Written

func (compressor *Compressor) Written() int

Written returns the number of bytes written to the compressor

func (*Compressor) WrittenBytes

func (compressor *Compressor) WrittenBytes() []byte

WrittenBytes returns the bytes written to the compressor This returns a pointer to the internal buffer, so it should not be modified

type Header struct {
	Version       uint16 // compressor release version
	NoCompression bool
}

Header is the header of a compressed data. It contains the compressor release version and the compression level.

func (*Header) ReadFrom

func (s *Header) ReadFrom(r io.Reader) (int64, error)

func (*Header) WriteTo

func (s *Header) WriteTo(w io.Writer) (int64, error)

Directories

Path Synopsis
internal
suffixarray
Package suffixarray implements substring search in logarithmic time using an in-memory suffix array.
Package suffixarray implements substring search in logarithmic time using an in-memory suffix array.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL