|
36 | 36 | _COMPRESS_LEVEL_FAST = isal_zlib.ISAL_BEST_SPEED
|
37 | 37 | _COMPRESS_LEVEL_TRADEOFF = isal_zlib.ISAL_DEFAULT_COMPRESSION
|
38 | 38 | _COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION
|
39 |
| -_BLOCK_SIZE = 64*1024 |
40 | 39 |
|
41 | 40 | BUFFER_SIZE = _compression.BUFFER_SIZE
|
42 | 41 |
|
@@ -95,9 +94,46 @@ def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
|
95 | 94 |
|
96 | 95 |
|
97 | 96 | 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 | + """ |
98 | 103 | def __init__(self, filename=None, mode=None,
|
99 | 104 | compresslevel=isal_zlib.ISAL_DEFAULT_COMPRESSION,
|
100 | 105 | 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 | + """ |
101 | 137 | if not (isal_zlib.ISAL_BEST_SPEED <= compresslevel
|
102 | 138 | <= isal_zlib.ISAL_BEST_COMPRESSION):
|
103 | 139 | raise ValueError(
|
@@ -257,7 +293,7 @@ def main():
|
257 | 293 | out_file = io.open(base, "wb")
|
258 | 294 | try:
|
259 | 295 | while True:
|
260 |
| - block = in_file.read(_BLOCK_SIZE) |
| 296 | + block = in_file.read(BUFFER_SIZE) |
261 | 297 | if block == b"":
|
262 | 298 | break
|
263 | 299 | out_file.write(block)
|
|
0 commit comments