Skip to content

Commit 0668d4a

Browse files
committed
Start documenting igzip
1 parent 126ab14 commit 0668d4a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

docs/igzip.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
igzip
2+
=========
3+
4+
.. automodule:: isal.igzip
5+
:members:

src/isal/igzip.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
_COMPRESS_LEVEL_FAST = isal_zlib.ISAL_BEST_SPEED
3737
_COMPRESS_LEVEL_TRADEOFF = isal_zlib.ISAL_DEFAULT_COMPRESSION
3838
_COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION
39-
_BLOCK_SIZE = 64*1024
4039

4140
BUFFER_SIZE = _compression.BUFFER_SIZE
4241

@@ -95,9 +94,46 @@ def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
9594

9695

9796
class IGzipFile(gzip.GzipFile):
97+
"""The IGzipFile class simulates most of the methods of a file object with
98+
the exception of the truncate() method.
99+
100+
This class only supports opening files in binary mode. If you need to open a
101+
compressed file in text mode, use the gzip.open() function.
102+
"""
98103
def __init__(self, filename=None, mode=None,
99104
compresslevel=isal_zlib.ISAL_DEFAULT_COMPRESSION,
100105
fileobj=None, mtime=None):
106+
"""Constructor for the IGzipFile class.
107+
108+
At least one of fileobj and filename must be given a
109+
non-trivial value.
110+
111+
The new class instance is based on fileobj, which can be a regular
112+
file, an io.BytesIO object, or any other object which simulates a file.
113+
It defaults to None, in which case filename is opened to provide
114+
a file object.
115+
116+
When fileobj is not None, the filename argument is only used to be
117+
included in the gzip file header, which may include the original
118+
filename of the uncompressed file. It defaults to the filename of
119+
fileobj, if discernible; otherwise, it defaults to the empty string,
120+
and in this case the original filename is not included in the header.
121+
122+
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x',
123+
or 'xb' depending on whether the file will be read or written.
124+
The default is the mode of fileobj if discernible; otherwise, the
125+
default is 'rb'. A mode of 'r' is equivalent to one of 'rb', and
126+
similarly for 'w' and 'wb', 'a' and 'ab', and 'x' and 'xb'.
127+
128+
The compresslevel argument is an integer from 0 to 3 controlling the
129+
level of compression; 0 is fastest and produces the least compression,
130+
and 3 is slowest and produces the most compression. Unlike
131+
gzip.GzipFile 0 is NOT no compression. The default is 2.
132+
133+
The mtime argument is an optional numeric timestamp to be written
134+
to the last modification time field in the stream when compressing.
135+
If omitted or None, the current time is used.
136+
"""
101137
if not (isal_zlib.ISAL_BEST_SPEED <= compresslevel
102138
<= isal_zlib.ISAL_BEST_COMPRESSION):
103139
raise ValueError(
@@ -257,7 +293,7 @@ def main():
257293
out_file = io.open(base, "wb")
258294
try:
259295
while True:
260-
block = in_file.read(_BLOCK_SIZE)
296+
block = in_file.read(BUFFER_SIZE)
261297
if block == b"":
262298
break
263299
out_file.write(block)

0 commit comments

Comments
 (0)