Skip to content

Commit 8a5b758

Browse files
committed
Allow setting the read buffer size
1 parent 828838e commit 8a5b758

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

profile_igzipreader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def main():
8+
igzip.READ_BUFFER_SIZE = 32 * 1024
89
with igzip.open(sys.argv[1], mode="rb") as gzip_h:
910
while True:
1011
block = gzip_h.read(32*1024)

src/isal/igzip.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
_COMPRESS_LEVEL_TRADEOFF = isal_zlib.ISAL_DEFAULT_COMPRESSION
4040
_COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION
4141

42+
READ_BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE
43+
4244
FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16
4345

4446
try:
@@ -152,7 +154,7 @@ def __init__(self, filename=None, mode=None,
152154
0)
153155
if self.mode == gzip.READ:
154156
raw = _IGzipReader(self.fileobj)
155-
self._buffer = io.BufferedReader(raw)
157+
self._buffer = io.BufferedReader(raw, buffer_size=READ_BUFFER_SIZE)
156158

157159
def __repr__(self):
158160
s = repr(self.fileobj)
@@ -273,7 +275,7 @@ def read(self, size=-1):
273275

274276
# Read a chunk of data from the file
275277
if self._decompressor.needs_input:
276-
buf = self._fp.read(io.DEFAULT_BUFFER_SIZE)
278+
buf = self._fp.read(READ_BUFFER_SIZE)
277279
uncompress = self._decompressor.decompress(buf, size)
278280
else:
279281
uncompress = self._decompressor.decompress(b"", size)
@@ -469,6 +471,8 @@ def main():
469471
elif not args.compress and args.file is not None:
470472
out_file = io.open(base, "wb")
471473

474+
global READ_BUFFER_SIZE
475+
READ_BUFFER_SIZE = args.buffer_size
472476
try:
473477
while True:
474478
block = in_file.read(args.buffer_size)

0 commit comments

Comments
 (0)