DefaultDictMax is the default maximum dictionary size in bytes used by the decoder. This value is sufficient to decompress files created with XZ Utils "xz -9".
const DefaultDictMax = 1 << 26 // 64 MiB
Package specific errors.
var ( ErrUnsupportedCheck = errors.New("xz: integrity check type not supported") ErrMemlimit = errors.New("xz: LZMA2 dictionary size exceeds max") ErrFormat = errors.New("xz: file format not recognized") ErrOptions = errors.New("xz: compression options not supported") ErrData = errors.New("xz: data is corrupt") ErrBuf = errors.New("xz: data is truncated or corrupt") )
CheckID is the type of the data integrity check in an XZ stream calculated from the uncompressed data.
type CheckID int
const ( CheckNone CheckID = 0x00 CheckCRC32 CheckID = 0x01 CheckCRC64 CheckID = 0x04 CheckSHA256 CheckID = 0x0A )
func (id CheckID) String() string
An XZ stream contains a stream header which holds information about the stream. That information is exposed as fields of the Reader. Currently it contains only the stream's data integrity check type.
type Header struct { CheckType CheckID // type of the stream's data integrity check }
A Reader is an io.Reader that can be used to retrieve uncompressed data from an XZ file.
In general, an XZ file can be a concatenation of other XZ files. Reads from the Reader return the concatenation of the uncompressed data of each.
type Reader struct { Header // contains filtered or unexported fields }
func NewReader(r io.Reader, dictMax uint32) (*Reader, error)
NewReader creates a new Reader reading from r. The decompressor will use an LZMA2 dictionary size up to dictMax bytes in size. Passing a value of zero sets dictMax to DefaultDictMax. If an individual XZ stream requires a dictionary size greater than dictMax in order to decompress, Read will return ErrMemlimit.
If NewReader is passed a value of nil for r then a Reader is created such that all read attempts will return io.EOF. This is useful if you just want to allocate memory for a Reader which will later be initialized with Reset.
Due to internal buffering, the Reader may read more data than necessary from r.
▹ Example
func (z *Reader) Multistream(ok bool)
Multistream controls whether the reader is operating in multistream mode.
If enabled (the default), the Reader expects the input to be a sequence of XZ streams, possibly interspersed with stream padding, which it reads one after another. The effect is that the concatenation of a sequence of XZ streams or XZ files is treated as equivalent to the compressed result of the concatenation of the sequence. This is standard behaviour for XZ readers.
Calling Multistream(false) disables this behaviour; disabling the behaviour can be useful when reading file formats that distinguish individual XZ streams. In this mode, when the Reader reaches the end of the stream, Read returns io.EOF. To start the next stream, call z.Reset(nil) followed by z.Multistream(false). If there is no next stream, z.Reset(nil) will return io.EOF.
▹ Example
func (z *Reader) Read(p []byte) (n int, err error)
func (z *Reader) Reset(r io.Reader) error
Reset, for non-nil values of io.Reader r, discards the Reader z's state and makes it equivalent to the result of its original state from NewReader, but reading from r instead. This permits reusing a Reader rather than allocating a new one.
If you wish to leave r unchanged use z.Reset(nil). This keeps r unchanged and ensures internal buffering is preserved. If the Reader was at the end of a stream it is then ready to read any follow on streams. If there are no follow on streams z.Reset(nil) returns io.EOF. If the Reader was not at the end of a stream then z.Reset(nil) does nothing.