lzma.LZMACompressor

class lzma.LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)

Create a compressor object, which can be used to compress data incrementally.

For a more convenient way of compressing a single chunk of data, see compress().

The format argument specifies what container format should be used. Possible values are:

  • FORMAT_XZ: The .xz container format.

    This is the default format.

  • FORMAT_ALONE: The legacy .lzma container format.

    This format is more limited than .xz – it does not support integrity checks or multiple filters.

  • FORMAT_RAW: A raw data stream, not using any container format.

    This format specifier does not support integrity checks, and requires that you always specify a custom filter chain (for both compression and decompression). Additionally, data compressed in this manner cannot be decompressed using FORMAT_AUTO (see LZMADecompressor).

The check argument specifies the type of integrity check to include in the compressed data. This check is used when decompressing, to ensure that the data has not been corrupted. Possible values are:

  • CHECK_NONE: No integrity check. This is the default (and the only acceptable value) for FORMAT_ALONE and FORMAT_RAW.
  • CHECK_CRC32: 32-bit Cyclic Redundancy Check.
  • CHECK_CRC64: 64-bit Cyclic Redundancy Check. This is the default for FORMAT_XZ.
  • CHECK_SHA256: 256-bit Secure Hash Algorithm.

If the specified check is not supported, an LZMAError is raised.

The compression settings can be specified either as a preset compression level (with the preset argument), or in detail as a custom filter chain (with the filters argument).

The preset argument (if provided) should be an integer between 0 and 9 (inclusive), optionally OR-ed with the constant PRESET_EXTREME. If neither preset nor filters are given, the default behavior is to use PRESET_DEFAULT (preset level 6). Higher presets produce smaller output, but make the compression process slower.

Note

In addition to being more CPU-intensive, compression with higher presets also requires much more memory (and produces output that needs more memory to decompress). With preset 9 for example, the overhead for an LZMACompressor object can be as high as 800 MiB. For this reason, it is generally best to stick with the default preset.

The filters argument (if provided) should be a filter chain specifier. See Specifying custom filter chains for details.

compress(data)

Compress data (a bytes object), returning a bytes object containing compressed data for at least part of the input. Some of data may be buffered internally, for use in later calls to compress() and flush(). The returned data should be concatenated with the output of any previous calls to compress().

flush()

Finish the compression process, returning a bytes object containing any data stored in the compressor’s internal buffers.

The compressor cannot be used after this method has been called.

doc_python
2016-10-07 17:36:28
Comments
Leave a Comment

Please login to continue.