1919# SOFTWARE.
2020
2121# cython: language_level=3
22+ # cython: binding=True
2223
23-
24+ """
25+ Implementation of the zlib module using the ISA-L libraries.
26+ """
2427import warnings
2528import zlib
2629
@@ -83,7 +86,14 @@ if ISAL_DEF_MAX_HIST_BITS > zlib.MAX_WBITS:
8386 " Please contact the developers." )
8487
8588
86- cpdef adler32(data, unsigned int value = 1 ):
89+ def adler32 (data , unsigned int value = 1 ):
90+ """
91+ Computes an Adler-32 checksum of *data*. Returns the checksum as unsigned
92+ 32-bit integer.
93+
94+ :param data: Binary data (bytes, bytearray, memoryview).
95+ :param value: The starting value of the checksum.
96+ """
8797 cdef Py_buffer buffer_data
8898 cdef Py_buffer* buffer = & buffer_data
8999 if PyObject_GetBuffer(data, buffer , PyBUF_READ & PyBUF_C_CONTIGUOUS) != 0 :
@@ -95,7 +105,14 @@ cpdef adler32(data, unsigned int value = 1):
95105 finally :
96106 PyBuffer_Release(buffer )
97107
98- cpdef crc32(data, unsigned int value = 0 ):
108+ def crc32 (data , unsigned int value = 0 ):
109+ """
110+ Computes a CRC-32 checksum of *data*. Returns the checksum as unsigned
111+ 32-bit integer.
112+
113+ :param data: Binary data (bytes, bytearray, memoryview).
114+ :param value: The starting value of the checksum.
115+ """
99116 cdef Py_buffer buffer_data
100117 cdef Py_buffer* buffer = & buffer_data
101118 if PyObject_GetBuffer(data, buffer , PyBUF_READ & PyBUF_C_CONTIGUOUS) != 0 :
@@ -130,6 +147,22 @@ cdef void arrange_input_buffer(stream_or_state *stream, Py_ssize_t *remains):
130147def compress (data ,
131148 int level = ISAL_DEFAULT_COMPRESSION_I,
132149 int wbits = ISAL_DEF_MAX_HIST_BITS):
150+ """
151+ Compresses the bytes in *data*. Returns a bytes object with the
152+ compressed data.
153+
154+ :param level: the compression level from 0 to 3. 0 is the lowest
155+ compression (NOT no compression as in stdlib zlib!) and the
156+ fastest. 3 is the best compression and the slowest. Default
157+ is a compromise at level 2.
158+
159+ :param wbits: Set the amount of history bits or window size and which
160+ headers and trailers are used. Values from 9 to 15 signify
161+ will use a zlib header and trailer. From +25 to +31
162+ (16 + 9 to 15) a gzip header and trailer will be used.
163+ -9 to -15 will generate a raw compressed string with
164+ no headers and trailers.
165+ """
133166 if level == ZLIB_DEFAULT_COMPRESSION_I:
134167 level = ISAL_DEFAULT_COMPRESSION_I
135168
@@ -199,10 +232,22 @@ def compress(data,
199232 PyMem_Free(level_buf)
200233 PyMem_Free(obuf)
201234
202- cpdef decompress(data,
235+ def decompress (data ,
203236 int wbits = ISAL_DEF_MAX_HIST_BITS,
204237 Py_ssize_t bufsize = DEF_BUF_SIZE,):
205-
238+ """
239+ Deompresses the bytes in *data*. Returns a bytes object with the
240+ decompressed data.
241+
242+ :param wbits: Set the amount of history bits or window size and which
243+ headers and trailers are expected. Values from 8 to 15
244+ will expect a zlib header and trailer. -8 to -15 will expect
245+ a raw compressed string with no headers and trailers.
246+ From +24 to +31 == 16 + (8 to 15) a gzip header and trailer
247+ will be expected. From +40 to +47 == 32 + (8 to 15)
248+ automatically detects a gzip or zlib header.
249+ :param bufsize: The initial size of the output buffer.
250+ """
206251 if bufsize < 0 :
207252 raise ValueError (" bufsize must be non-negative" )
208253
@@ -263,17 +308,41 @@ cpdef decompress(data,
263308 PyMem_Free(obuf)
264309
265310
266- cpdef decompressobj(int wbits = ISAL_DEF_MAX_HIST_BITS,
311+ def decompressobj (int wbits = ISAL_DEF_MAX_HIST_BITS,
267312 zdict = None ):
313+
268314 return Decompress.__new__ (Decompress, wbits, zdict)
269315
270316
271- cpdef compressobj(int level = ISAL_DEFAULT_COMPRESSION,
272- int method = DEFLATED,
273- int wbits = ISAL_DEF_MAX_HIST_BITS,
274- int memLevel = DEF_MEM_LEVEL,
275- int strategy = zlib.Z_DEFAULT_STRATEGY,
276- zdict = None ):
317+ def compressobj (int level = ISAL_DEFAULT_COMPRESSION,
318+ int method = DEFLATED,
319+ int wbits = ISAL_DEF_MAX_HIST_BITS,
320+ int memLevel = DEF_MEM_LEVEL,
321+ int strategy = zlib.Z_DEFAULT_STRATEGY,
322+ zdict = None ):
323+ """
324+ Returns a compression object for compressing data streams.
325+
326+ :param level: the compression level from 0 to 3. 0 is the lowest
327+ compression (NOT no compression as in stdlib zlib!) and the
328+ fastest. 3 is the best compression and the slowest. Default
329+ is a compromise at level 2.
330+ :param method: The compression algorithm. Currently only DEFLATED is
331+ supported.
332+ :param wbits: Set the amount of history bits or window size and which
333+ headers and trailers are used. Values from 9 to 15 signify
334+ will use a zlib header and trailer. From +25 to +31
335+ (16 + 9 to 15) a gzip header and trailer will be used.
336+ -9 to -15 will generate a raw compressed string with
337+ no headers and trailers.
338+ :param memLevel: The amount of memory used for the internal compression
339+ state. Higher values use more memory for better speed and
340+ smaller output.
341+ :zdict: A predefined compression dictionary. A sequence of bytes
342+ that are expected to occur frequently in the to be
343+ compressed data. The most common subsequences should come
344+ at the end.
345+ """
277346 return Compress.__new__ (Compress, level, method, wbits, memLevel, strategy, zdict)
278347
279348
0 commit comments