Python Glossary Русский

Python 3.14+compression.zstdterm

compression.zstd.DecompressionParameter

compression parameters

An enum of zstd decompression settings for the options dict; in practice a single one, window_log_max, the memory limit for the window.

Syntax

options={DecompressionParameter.window_log_max: N}

By default the decompressor refuses frames that need a window larger than 2**27 bytes (128 MiB): it protects against memory bombs. If data was stream-compressed with a large window_log (for long distance matching, say), you get ZstdError "Frame requires too much memory" unless you set window_log_max. Raise the limit only for your own data: for untrusted input it is the protection.

Examples

# Python 3.14+
from compression import zstd  # → ? нужна сборка CPython с libzstd
data = b'hello zstd ' * 100
comp = zstd.ZstdCompressor(options={zstd.CompressionParameter.window_log: 28})
frame = comp.compress(data) + comp.flush()
try:
    zstd.decompress(frame)
except zstd.ZstdError as e:
    print(e)  # → Unable to decompress Zstandard data: Frame requires too much memory for decoding
opts = {zstd.DecompressionParameter.window_log_max: 28}
print(zstd.decompress(frame, options=opts) == data)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy