API Documentation: isal_zlib

Implementation of the zlib module using the ISA-L libraries.

class isal.isal_zlib.Compress

Compress object for handling streaming compression.

compress(data)

Compress data returning a bytes object with at least part of the data in data. This data should be concatenated to the output produced by any preceding calls to the compress() method. Some input may be kept in internal buffers for later processing.

flush(mode)

All pending input is processed, and a bytes object containing the remaining compressed output is returned.

Parameters

mode – Defaults to ISAL_FULL_FLUSH (Z_FINISH equivalent) which finishes the compressed stream and prevents compressing any more data. The only other supported method is ISAL_SYNC_FLUSH (Z_SYNC_FLUSH) equivalent.

class isal.isal_zlib.Decompress

Decompress object for handling streaming decompression.

decompress(data, max_length)

Decompress data, returning a bytes object containing the uncompressed data corresponding to at least part of the data in string.

Parameters

max_length – if non-zero then the return value will be no longer than max_length. Unprocessed data will be in the unconsumed_tail attribute.

flush(length)

All pending input is processed, and a bytes object containing the remaining uncompressed output is returned.

Parameters

length – The initial size of the output buffer.

exception isal.isal_zlib.IsalError

Exception raised on compression and decompression errors.

isal.isal_zlib.adler32(data, value=1)

Computes an Adler-32 checksum of data. Returns the checksum as unsigned 32-bit integer.

Parameters
  • data – Binary data (bytes, bytearray, memoryview).

  • value – The starting value of the checksum.

isal.isal_zlib.compress(data, level=2, wbits=15)

Compresses the bytes in data. Returns a bytes object with the compressed data.

Parameters
  • level – the compression level from 0 to 3. 0 is the lowest compression (NOT no compression as in stdlib zlib!) and the fastest. 3 is the best compression and the slowest. Default is a compromise at level 2.

  • wbits – Set the amount of history bits or window size and which headers and trailers are used. Values from 9 to 15 signify will use a zlib header and trailer. From +25 to +31 (16 + 9 to 15) a gzip header and trailer will be used. -9 to -15 will generate a raw compressed string with no headers and trailers.

isal.isal_zlib.compressobj(level=2, method=8, wbits=15, memLevel=8, strategy=0, zdict=None)

Returns a Compress object for compressing data streams.

Parameters
  • level – the compression level from 0 to 3. 0 is the lowest compression (NOT no compression as in stdlib zlib!) and the fastest. 3 is the best compression and the slowest. Default is a compromise at level 2.

  • method – The compression algorithm. Currently only DEFLATED is supported.

  • wbits – Set the amount of history bits or window size and which headers and trailers are used. Values from 9 to 15 signify will use a zlib header and trailer. From +25 to +31 (16 + 9 to 15) a gzip header and trailer will be used. -9 to -15 will generate a raw compressed string with no headers and trailers.

  • memLevel – The amount of memory used for the internal compression state. Higher values use more memory for better speed and smaller output.

Zdict

A predefined compression dictionary. A sequence of bytes that are expected to occur frequently in the to be compressed data. The most common subsequences should come at the end.

isal.isal_zlib.crc32(data, value=0)

Computes a CRC-32 checksum of data. Returns the checksum as unsigned 32-bit integer.

Parameters
  • data – Binary data (bytes, bytearray, memoryview).

  • value – The starting value of the checksum.

isal.isal_zlib.decompress(data, wbits=15, bufsize=16384)

Deompresses the bytes in data. Returns a bytes object with the decompressed data.

Parameters
  • wbits – Set the amount of history bits or window size and which headers and trailers are expected. Values from 8 to 15 will expect a zlib header and trailer. -8 to -15 will expect a raw compressed string with no headers and trailers. From +24 to +31 == 16 + (8 to 15) a gzip header and trailer will be expected. From +40 to +47 == 32 + (8 to 15) automatically detects a gzip or zlib header.

  • bufsize – The initial size of the output buffer.

isal.isal_zlib.decompressobj(wbits=15, zdict=None)

Returns a Decompress object for decompressing data streams.

Parameters

wbits – Set the amount of history bits or window size and which headers and trailers are expected. Values from 8 to 15 will expect a zlib header and trailer. -8 to -15 will expect a raw compressed string with no headers and trailers. From +24 to +31 == 16 + (8 to 15) a gzip header and trailer will be expected. From +40 to +47 == 32 + (8 to 15) automatically detects a gzip or zlib header.

Zdict

A predefined compression dictionary. Must be the same zdict as was used to compress the data.

isal.isal_zlib.error

alias of isal.isal_zlib.IsalError