Skip to content

Commit 126ab14

Browse files
committed
Complete docstrings for isal_zlib
1 parent 03a2ffa commit 126ab14

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/isal/isal_zlib.pyx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ ISAL_FULL_FLUSH=FULL_FLUSH
7171

7272
Z_NO_FLUSH=ISAL_NO_FLUSH
7373
Z_SYNC_FLUSH=ISAL_SYNC_FLUSH
74-
Z_FULL_FLUSH=ISAL_FULL_FLUSH
7574
Z_FINISH=ISAL_FULL_FLUSH
7675

7776
class IsalError(OSError):
77+
"""Exception raised on compression and decompression errors."""
7878
pass
7979

8080
# Add error for compatibility
@@ -311,6 +311,19 @@ def decompress(data,
311311

312312
def decompressobj(int wbits=ISAL_DEF_MAX_HIST_BITS,
313313
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+
"""
314327
return Decompress.__new__(Decompress, wbits, zdict)
315328

316329

@@ -321,7 +334,7 @@ def compressobj(int level=ISAL_DEFAULT_COMPRESSION,
321334
int strategy=zlib.Z_DEFAULT_STRATEGY,
322335
zdict = None):
323336
"""
324-
Returns a compression object for compressing data streams.
337+
Returns a Compress object for compressing data streams.
325338
326339
:param level: the compression level from 0 to 3. 0 is the lowest
327340
compression (NOT no compression as in stdlib zlib!) and the
@@ -347,6 +360,7 @@ def compressobj(int level=ISAL_DEFAULT_COMPRESSION,
347360

348361

349362
cdef class Compress:
363+
"""Compress object for handling streaming compression."""
350364
cdef isal_zstream stream
351365
cdef unsigned char * level_buf
352366
cdef unsigned char * obuf
@@ -393,6 +407,12 @@ cdef class Compress:
393407
PyMem_Free(self.level_buf)
394408

395409
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+
"""
396416
# Initialise output buffer
397417
out = []
398418

@@ -431,13 +451,23 @@ cdef class Compress:
431451
PyBuffer_Release(buffer)
432452

433453
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+
"""
434463
if mode == NO_FLUSH:
435464
# Flushing with no_flush does nothing.
436465
return b""
437466

438-
# Initialise stream
467+
if mode == FULL_FLUSH:
468+
self.stream.end_of_stream = 1
439469
self.stream.flush = mode
440-
self.stream.end_of_stream = 1
470+
441471
# Initialise output buffer
442472
out = []
443473

@@ -457,6 +487,7 @@ cdef class Compress:
457487
return b"".join(out)
458488

459489
cdef class Decompress:
490+
"""Decompress object for handling streaming decompression."""
460491
cdef public bytes unused_data
461492
cdef public bytes unconsumed_tail
462493
cdef public bint eof
@@ -514,6 +545,14 @@ cdef class Decompress:
514545
self.unconsumed_tail = new_data
515546

516547
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+
"""
517556

518557
cdef Py_ssize_t total_bytes = 0
519558
if max_length == 0:
@@ -580,6 +619,12 @@ cdef class Decompress:
580619
PyBuffer_Release(buffer)
581620

582621
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+
"""
583628
if length <= 0:
584629
raise ValueError("Length must be greater than 0")
585630
if length > UINT32_MAX:

0 commit comments

Comments
 (0)