Documentation
¶
Overview ¶
Package lzma provides support for the encoding and decoding LZMA, LZMA2 and raw LZMA streams without a header.
Index ¶
- Constants
- Variables
- func DecodeDictSize(c byte) (n int64, err error)
- func EncodeDictSize(n int64) byte
- func NewRawReader(z io.Reader, dictSize int, props Properties, uncompressedSize uint64) (r io.Reader, err error)
- func NewRawWriter(z io.Writer, seq lz.Sequencer, p Properties, eos bool) (w io.WriteCloser, err error)
- func NewReader(z io.Reader) (r io.Reader, err error)
- func NewReader2(z io.Reader, dictSize int) (r io.ReadCloser, err error)
- func NewReader2Config(z io.Reader, cfg Reader2Config) (r io.ReadCloser, err error)
- func NewWriter(z io.Writer) (w io.WriteCloser, err error)
- func NewWriterConfig(z io.Writer, cfg WriterConfig) (w io.WriteCloser, err error)
- func TestWriter2ConfigDictSize(t *testing.T)
- type Properties
- type Reader2Config
- type Writer2
- type Writer2Config
- type WriterConfig
Constants ¶
const EOSSize uint64 = 1<<64 - 1
EOSSize marks a stream that requires the EOS marker to identify the end of the stream. It is used by NewRawReader.
Variables ¶
var ErrEncoding = errors.New("lzma: wrong encoding")
ErrEncoding reports an encoding error
Functions ¶
func DecodeDictSize ¶
DecodeDictSize decodes the encoded dictionary capacity. The function returns an error if the code is out of range.
func EncodeDictSize ¶
EncodeDictSize encodes a dictionary capacity. The function returns the code for the capacity that is greater or equal n. If n exceeds the maximum support dictionary capacity, the maximum value is returned.
func NewRawReader ¶
func NewRawReader(z io.Reader, dictSize int, props Properties, uncompressedSize uint64) (r io.Reader, err error)
NewRawReader returns a reader that can read a LZMA stream. For a stream with an EOS marker use EOSSize for uncompressedSize. The dictSize must be positive (>=0).
func NewRawWriter ¶
func NewRawWriter(z io.Writer, seq lz.Sequencer, p Properties, eos bool) (w io.WriteCloser, err error)
NewRawWriter writes only compress data stream. The argument eos controls whether an end of stream marker will be written.
func NewReader2 ¶ added in v0.4.1
NewReader2 creates a LZMA2 reader. Note that the interface is a ReadCloser, so it has to be closed after usage.
func NewReader2Config ¶
func NewReader2Config(z io.Reader, cfg Reader2Config) (r io.ReadCloser, err error)
NewReader2Config generates an LZMA2 reader using the configuration parameter attribute. Note that the code returns a ReadCloser, which has to be closed after reading.
func NewWriter ¶
func NewWriter(z io.Writer) (w io.WriteCloser, err error)
NewWriter creates a new LZMA writer.
func NewWriterConfig ¶
func NewWriterConfig(z io.Writer, cfg WriterConfig) (w io.WriteCloser, err error)
NewWriterConfig creates a new LZMA writer using the parameter provided by cfg.
Types ¶
type Properties ¶
Properties define the properties for the LZMA and LZMA2 compression.
func (Properties) Verify ¶ added in v0.4.1
func (p Properties) Verify() error
Verify verifies the correctness of the properties. It doesn't check the LZMA2 condition that LC + LP <= 4.
type Reader2Config ¶ added in v0.5.1
type Reader2Config struct { // DictSize provides the maximum dictionary size supported. DictSize int // Workers gives the maximum number of decompressing workers. Workers int // WorkerBufferSize give the maximum size of uncompressed data that can be // decoded by a single worker. WorkerBufferSize int }
Reader2Config provides the dictionary size parameter for a LZMA2 reader.
Note that the parallel decoding will only work if the stream has been encoded with multiple workers and the WorkerBufferSize is large enough. If the worker buffer size is too small no worker thread will be used for decompression.
func (*Reader2Config) SetDefaults ¶
func (cfg *Reader2Config) SetDefaults()
SetDefaults sets a default value for the dictionary size. Note that multi-threaded readers are not the default.
func (*Reader2Config) Verify ¶ added in v0.5.1
func (cfg *Reader2Config) Verify() error
Verify checks the validity of dictionary size.
type Writer2 ¶ added in v0.4.1
type Writer2 interface { io.WriteCloser Flush() error DictSize() int }
Writer2 is an interface that can Write, Close and Flush.
func NewWriter2 ¶ added in v0.4.1
NewWriter2 generates an LZMA2 writer for the default configuration.
func NewWriter2Config ¶
func NewWriter2Config(z io.Writer, cfg Writer2Config) (w Writer2, err error)
NewWriter2Config constructs an LZMA2 writer for a specific configuration. Note that the implementation for cfg.Workers > 1 uses go routines.
type Writer2Config ¶ added in v0.5.1
type Writer2Config struct { // DictSize sets the dictionary size. DictSize int // Properties for the LZMA algorithm. Properties Properties // ZeroProperties indicate that the Properties is indeed zero ZeroProperties bool // Number of workers processing data. Workers int // Size of buffer used by the worker. WorkerBufferSize int // Configuration for the LZ compressor. LZ lz.SeqConfig }
Writer2Config provides the configuration parameters for an LZMA2 writer.
func (*Writer2Config) SetDefaults ¶
func (cfg *Writer2Config) SetDefaults()
SetDefaults replaces zero values with default values. The workers variable will be set to the number of CPUs.
func (*Writer2Config) Verify ¶ added in v0.5.1
func (cfg *Writer2Config) Verify() error
Verify checks whether the configuration is consistent and correct. Usually call SetDefaults before this method.
type WriterConfig ¶ added in v0.5.1
type WriterConfig struct { // Dictionary size. DictSize int // Properties of the LZMA algorithm. Properties Properties // If true the properties are actually zero. ZeroProperties bool // FixedSize says that the stream has a fixed size know before // compression. FixedSize bool // Size gives the actual size if FixedSize is set. Size int64 // LZ specific configuration for the LZ sequencer. LZ lz.SeqConfig }
WriterConfig defines the parameters for the LZMA Writer.
func (*WriterConfig) SetDefaults ¶
func (cfg *WriterConfig) SetDefaults()
SetDefaults applies the defaults to the configuration if they have not been set previously.
func (*WriterConfig) Verify ¶ added in v0.5.1
func (cfg *WriterConfig) Verify() error
Verify checks the validity of the writer configuration parameter.