Skip to content

Commit 3803437

Browse files
authored
Merge pull request #12 from rhpvorderman/docs
Add API documentation
2 parents 5cadf25 + 3c2cc6e commit 3803437

File tree

8 files changed

+212
-33
lines changed

8 files changed

+212
-33
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
1010
version 0.1.0-dev
1111
-----------------
12+
+ Add API documentation.
1213
+ Ensure the igzip module is fully compatible with the gzip stdlib module.
1314
+ Add compliance tests from CPython to ensure isal_zlib and igzip are validated
1415
to the same standards as the zlib and gzip modules.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# Add any Sphinx extension module names here, as strings. They can be
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3333
# ones.
34-
extensions = [
34+
extensions = ["sphinx.ext.autodoc"
3535
]
3636

3737
# Add any paths that contain templates here, relative to this directory.

docs/igzip.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
API-documentation: igzip
2+
========================
3+
4+
.. automodule:: isal.igzip
5+
:members: compress, decompress, open
6+
7+
.. autoclass:: IGzipFile
8+
:members:
9+
:special-members: __init__

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Welcome to python-isal's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13+
isal_zlib
14+
igzip
15+
1316

1417

1518
Indices and tables

docs/isal_zlib.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
API Documentation: isal_zlib
2+
============================
3+
4+
.. automodule:: isal.isal_zlib
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
101+
a 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)