
Higher presets produce smaller output, but make the compression process If neither preset nor filters are given, theĭefault behavior is to use PRESET_DEFAULT (preset level 6). The preset argument (if provided) should be an integer between 0 andĩ (inclusive), optionally OR-ed with the constant Level (with the preset argument), or in detail as a custom filter chain The compression settings can be specified either as a preset compression If the specified check is not supported, an LZMAError is raised. This is the default (and the only acceptable value) forĬHECK_CRC32: 32-bit Cyclic Redundancy Check.ĬHECK_CRC64: 64-bit Cyclic Redundancy Check.ĬHECK_SHA256: 256-bit Secure Hash Algorithm. This check is used when decompressing, to ensure that theĭata has not been corrupted. The check argument specifies the type of integrity check to include in theĬompressed data. Additionally, data compressed in this manner cannot beĭecompressed using FORMAT_AUTO (see LZMADecompressor). You always specify a custom filter chain (for both compression andĭecompression). This format specifier does not support integrity checks, and requires that FORMAT_RAW: A raw data stream, not using any container format.The format argument specifies what container format should be used. LZMACompressor ( format = FORMAT_XZ, check = - 1, preset = None, filters = None ) ¶Ĭreate a compressor object, which can be used to compress data incrementally.įor a more convenient way of compressing a single chunk of data, see Compressing and decompressing data in memory ¶ class lzma. Number of bytes returned is unspecified (the size argument is ignored).Ĭhanged in version 3.6: Accepts a path-like object. At least oneīyte of data will be returned, unless EOF has been reached. Return buffered data without advancing the file position. The following method is also provided: peek ( size = - 1 ) ¶

Iteration and the with statement are supported. LZMAFile supports all the members specified by When opening a file for reading, the input file may be the concatenation of "w" does not truncate the file, and is instead equivalent to "a". If filename is a file object (rather than an actual file name), a mode of TheseĬan equivalently be given as "rb", "wb", "xb" and "ab" Overwriting, "x" for exclusive creation, or "a" for appending. The mode argument can be either "r" for reading (default), "w" for When wrapping anĮxisting file object, the wrapped file will not be closed when the Object to wrap, or the name of the file to open (as a str,īytes or path-like object). The filename argument specifies either the file Open an LZMA-compressed file in binary mode.Īn LZMAFile can wrap an already-open file object, or operateĭirectly on a named file. LZMAFile ( filename = None, mode = 'r', *, format = None, check = - 1, preset = None, filters = None ) ¶ Io.TextIOWrapper instance with the specified encoding, errorĬhanged in version 3.6: Accepts a path-like object. In this case, the encoding,Įrrors and newline arguments must not be provided.įor text mode, a LZMAFile object is created, and wrapped in an When opening a file for writing, the format, check, preset andįilters arguments have the same meanings as for LZMACompressor.įor binary mode, this function is equivalent to the LZMAFileĬonstructor: LZMAFile(filename, mode. The same meanings as for LZMADecompressor. When opening a file for reading, the format and filters arguments have

"x", "xb", "a" or "ab" for binary mode, or "rt", The mode argument can be any of "r", "rb", "w", "wb", Which case the named file is opened, or it can be an existing file object The filename argument can be either an actual file name (given as a Open an LZMA-compressed file in binary or text mode, returning a file open ( filename, mode = 'rb', *, format = None, check = - 1, preset = None, filters = None, encoding = None, errors = None, newline = None ) ¶ Reading and writing compressed files ¶ lzma. This exception is raised when an error occurs during compression orĭecompression, or while initializing the compressor/decompressor state. Thread-safe, so if you need to use a single LZMAFile instanceįrom multiple threads, it is necessary to protect it with a lock. Note that LZMAFile and bz2.BZ2File are not The interface provided by this module is very similar to that of the bz2 Xz utility, as well as raw compressed streams. This module provides classes and convenience functions for compressing andĭecompressing data using the LZMA compression algorithm.
