Skip to content

Commit 99a9d39

Browse files
authored
Merge pull request #39 from pycompression/clibuffer
Bigger buffer for the Command Line interface.
2 parents f688a15 + 00c9791 commit 99a9d39

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changelog
99
1010
version 0.5.0-dev
1111
-----------------
12+
+ The command-line interface now reads in blocks of 32K instead of 8K. This
13+
improves performance by about 6% when compressing and 11% when decompressing.
14+
A hidden ``-b`` flag was added to adjust the buffer size for benchmarks.
1215
+ A ``-c`` or ``--stdout`` flag was added to the CLI interface of isal.igzip.
1316
This allows it to behave more like the ``gzip`` or ``pigz`` command line
1417
interfaces.

src/isal/igzip.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import os
2828
import sys
2929

30-
import _compression
31-
3230
from . import isal_zlib
3331

3432
__all__ = ["IGzipFile", "open", "compress", "decompress", "BadGzipFile"]
@@ -37,8 +35,6 @@
3735
_COMPRESS_LEVEL_TRADEOFF = isal_zlib.ISAL_DEFAULT_COMPRESSION
3836
_COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION
3937

40-
BUFFER_SIZE = _compression.BUFFER_SIZE
41-
4238
try:
4339
BadGzipFile = gzip.BadGzipFile
4440
except AttributeError: # Versions lower than 3.8 do not have BadGzipFile
@@ -278,6 +274,12 @@ def main():
278274
help="Decompress the file instead of compressing.")
279275
parser.add_argument("-c", "--stdout", action="store_true",
280276
help="write on standard output")
277+
# -b flag not taken by either gzip or igzip. Hidden attribute. Above 32K
278+
# diminishing returns hit. _compression.BUFFER_SIZE = 8k. But 32K is about
279+
# ~6% faster.
280+
parser.add_argument("-b", "--buffer-size",
281+
default=32 * 1024, type=int,
282+
help=argparse.SUPPRESS)
281283
args = parser.parse_args()
282284

283285
compresslevel = args.compresslevel or _COMPRESS_LEVEL_TRADEOFF
@@ -310,7 +312,7 @@ def main():
310312

311313
try:
312314
while True:
313-
block = in_file.read(BUFFER_SIZE)
315+
block = in_file.read(args.buffer_size)
314316
if block == b"":
315317
break
316318
out_file.write(block)

0 commit comments

Comments
 (0)