@@ -71,10 +71,10 @@ ISAL_FULL_FLUSH=FULL_FLUSH
71
71
72
72
Z_NO_FLUSH= ISAL_NO_FLUSH
73
73
Z_SYNC_FLUSH= ISAL_SYNC_FLUSH
74
- Z_FULL_FLUSH= ISAL_FULL_FLUSH
75
74
Z_FINISH= ISAL_FULL_FLUSH
76
75
77
76
class IsalError (OSError ):
77
+ """ Exception raised on compression and decompression errors."""
78
78
pass
79
79
80
80
# Add error for compatibility
@@ -311,6 +311,19 @@ def decompress(data,
311
311
312
312
def decompressobj (int wbits = ISAL_DEF_MAX_HIST_BITS,
313
313
zdict = None ):
314
+ """
315
+ Returns a Decompress object for decompressing data streams.
316
+
317
+ :param wbits: Set the amount of history bits or window size and which
318
+ headers and trailers are expected. Values from 8 to 15
319
+ will expect a zlib header and trailer. -8 to -15 will expect
320
+ a raw compressed string with no headers and trailers.
321
+ From +24 to +31 == 16 + (8 to 15) a gzip header and trailer
322
+ will be expected. From +40 to +47 == 32 + (8 to 15)
323
+ automatically detects a gzip or zlib header.
324
+ :zdict: A predefined compression dictionary. Must be the same zdict
325
+ as was used to compress the data.
326
+ """
314
327
return Decompress.__new__ (Decompress, wbits, zdict)
315
328
316
329
@@ -321,7 +334,7 @@ def compressobj(int level=ISAL_DEFAULT_COMPRESSION,
321
334
int strategy = zlib.Z_DEFAULT_STRATEGY,
322
335
zdict = None ):
323
336
"""
324
- Returns a compression object for compressing data streams.
337
+ Returns a Compress object for compressing data streams.
325
338
326
339
:param level: the compression level from 0 to 3. 0 is the lowest
327
340
compression (NOT no compression as in stdlib zlib!) and the
@@ -347,6 +360,7 @@ def compressobj(int level=ISAL_DEFAULT_COMPRESSION,
347
360
348
361
349
362
cdef class Compress:
363
+ """ Compress object for handling streaming compression."""
350
364
cdef isal_zstream stream
351
365
cdef unsigned char * level_buf
352
366
cdef unsigned char * obuf
@@ -393,6 +407,12 @@ cdef class Compress:
393
407
PyMem_Free(self .level_buf)
394
408
395
409
def compress (self , data ):
410
+ """
411
+ Compress *data* returning a bytes object with at least part of the
412
+ data in *data*. This data should be concatenated to the output
413
+ produced by any preceding calls to the compress() method.
414
+ Some input may be kept in internal buffers for later processing.
415
+ """
396
416
# Initialise output buffer
397
417
out = []
398
418
@@ -431,13 +451,23 @@ cdef class Compress:
431
451
PyBuffer_Release(buffer )
432
452
433
453
def flush (self , int mode = FULL_FLUSH):
454
+ """
455
+ All pending input is processed, and a bytes object containing the
456
+ remaining compressed output is returned.
457
+
458
+ :param mode: Defaults to ISAL_FULL_FLUSH (Z_FINISH equivalent) which
459
+ finishes the compressed stream and prevents compressing
460
+ any more data. The only other supported method is
461
+ ISAL_SYNC_FLUSH (Z_SYNC_FLUSH) equivalent.
462
+ """
434
463
if mode == NO_FLUSH:
435
464
# Flushing with no_flush does nothing.
436
465
return b" "
437
466
438
- # Initialise stream
467
+ if mode == FULL_FLUSH:
468
+ self .stream.end_of_stream = 1
439
469
self .stream.flush = mode
440
- self .stream.end_of_stream = 1
470
+
441
471
# Initialise output buffer
442
472
out = []
443
473
@@ -457,6 +487,7 @@ cdef class Compress:
457
487
return b" " .join(out)
458
488
459
489
cdef class Decompress:
490
+ """ Decompress object for handling streaming decompression."""
460
491
cdef public bytes unused_data
461
492
cdef public bytes unconsumed_tail
462
493
cdef public bint eof
@@ -514,6 +545,14 @@ cdef class Decompress:
514
545
self .unconsumed_tail = new_data
515
546
516
547
def decompress (self , data , Py_ssize_t max_length = 0 ):
548
+ """
549
+ Decompress data, returning a bytes object containing the uncompressed
550
+ data corresponding to at least part of the data in string.
551
+
552
+ :param max_length: if non-zero then the return value will be no longer
553
+ than max_length. Unprocessed data will be in the
554
+ unconsumed_tail attribute.
555
+ """
517
556
518
557
cdef Py_ssize_t total_bytes = 0
519
558
if max_length == 0 :
@@ -580,6 +619,12 @@ cdef class Decompress:
580
619
PyBuffer_Release(buffer )
581
620
582
621
def flush (self , Py_ssize_t length = DEF_BUF_SIZE):
622
+ """
623
+ All pending input is processed, and a bytes object containing the
624
+ remaining uncompressed output is returned.
625
+
626
+ :param length: The initial size of the output buffer.
627
+ """
583
628
if length <= 0 :
584
629
raise ValueError (" Length must be greater than 0" )
585
630
if length > UINT32_MAX:
0 commit comments