19
19
# SOFTWARE.
20
20
21
21
# cython: language_level=3
22
+ # cython: binding=True
22
23
23
-
24
+ """
25
+ Implementation of the zlib module using the ISA-L libraries.
26
+ """
24
27
import warnings
25
28
import zlib
26
29
@@ -83,7 +86,14 @@ if ISAL_DEF_MAX_HIST_BITS > zlib.MAX_WBITS:
83
86
" Please contact the developers." )
84
87
85
88
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
+ """
87
97
cdef Py_buffer buffer_data
88
98
cdef Py_buffer* buffer = & buffer_data
89
99
if PyObject_GetBuffer(data, buffer , PyBUF_READ & PyBUF_C_CONTIGUOUS) != 0 :
@@ -95,7 +105,14 @@ cpdef adler32(data, unsigned int value = 1):
95
105
finally :
96
106
PyBuffer_Release(buffer )
97
107
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
+ """
99
116
cdef Py_buffer buffer_data
100
117
cdef Py_buffer* buffer = & buffer_data
101
118
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):
130
147
def compress (data ,
131
148
int level = ISAL_DEFAULT_COMPRESSION_I,
132
149
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
+ """
133
166
if level == ZLIB_DEFAULT_COMPRESSION_I:
134
167
level = ISAL_DEFAULT_COMPRESSION_I
135
168
@@ -199,10 +232,22 @@ def compress(data,
199
232
PyMem_Free(level_buf)
200
233
PyMem_Free(obuf)
201
234
202
- cpdef decompress(data,
235
+ def decompress (data ,
203
236
int wbits = ISAL_DEF_MAX_HIST_BITS,
204
237
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
+ """
206
251
if bufsize < 0 :
207
252
raise ValueError (" bufsize must be non-negative" )
208
253
@@ -263,17 +308,41 @@ cpdef decompress(data,
263
308
PyMem_Free(obuf)
264
309
265
310
266
- cpdef decompressobj(int wbits = ISAL_DEF_MAX_HIST_BITS,
311
+ def decompressobj (int wbits = ISAL_DEF_MAX_HIST_BITS,
267
312
zdict = None ):
313
+
268
314
return Decompress.__new__ (Decompress, wbits, zdict)
269
315
270
316
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
+ """
277
346
return Compress.__new__ (Compress, level, method, wbits, memLevel, strategy, zdict)
278
347
279
348
0 commit comments