Python Glossary Русский

Python 3.3+lzmafunction

lzma.decompress()

in-memory compression

Decompresses LZMA/XZ data in a single call; by default the format is detected automatically and concatenated streams are joined.

Syntax

data = lzma.decompress(data, format=FORMAT_AUTO, memlimit=None, filters=None)

Corrupt input raises lzma.LZMAError, not OSError as in bz2 — the compression modules raise different exceptions. An explicit format=FORMAT_XZ rejects .lzma data with the same error, so do not set the format without a reason. For untrusted data use LZMADecompressor with memlimit and max_length.

Examples

import lzma
print(lzma.decompress(lzma.compress(b'a') + lzma.compress(b'b')))  # → b'ab'
try:
    lzma.decompress(b'garbage')
except lzma.LZMAError as e:
    print(e)  # → Input format not supported by decoder

See also

Open in the full glossarydocs.python.orgReport an inaccuracy