Python Glossary Русский

Python 3.3+lzmaterm

lzma.LZMADecompressor

streaming compression

An object for streaming LZMA/XZ decompression; by default it detects the input format itself.

Syntax

d = lzma.LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)

One object, one stream: at the end eof=True, extra bytes sit in unused_data, and another call gives EOFError. The check attribute tells which checksum the stream carries, but it is known only after the header has been parsed. memlimit caps the decoder's memory and protects against archives made with a huge dictionary.

Examples

import lzma
d = lzma.LZMADecompressor()
packed = lzma.compress(b'payload', check=lzma.CHECK_SHA256)
print(d.decompress(packed + b'extra'), d.eof, d.unused_data)  # → b'payload' True b'extra'
print(d.check == lzma.CHECK_SHA256)  # → True
try:
    d.decompress(b'x')
except EOFError as e:
    print(e)  # → Already at end of stream

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy