Skip to content

Commit f486e2b

Browse files
committed
Use a much simpler readinto implementation
1 parent 046b719 commit f486e2b

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/isal/igzip_threaded.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF,
1919

2020

2121
class ThreadedGzipReader(io.RawIOBase):
22-
def __init__(self, fp, queue_size = 8, block_size = 128 * 1024):
22+
def __init__(self, fp, queue_size=4, block_size=8 * 1024 * 1024):
2323
self.raw = fp
24-
self.fileobj = igzip._IGzipReader(fp, 512 * 1024)
24+
self.fileobj = igzip._IGzipReader(fp, buffersize=8 * 1024 * 1024)
2525
self.pos = 0
2626
self.read_file = False
2727
self.queue = queue.Queue(queue_size)
@@ -46,11 +46,9 @@ def _decompress(self):
4646
return
4747
block_queue.put(data)
4848

49-
def read(self, size: int = -1) -> bytes:
50-
if size < 0:
51-
return self.readall()
52-
data = self.buffer.read(size)
53-
if not data:
49+
def readinto(self, b):
50+
result = self.buffer.readinto(b)
51+
if result == 0:
5452
while True:
5553
try:
5654
data_from_queue = self.queue.get(timeout=0.01)
@@ -60,17 +58,10 @@ def read(self, size: int = -1) -> bytes:
6058
if self.exception:
6159
raise self.exception
6260
# EOF reached
63-
return b""
61+
return 0
6462
self.buffer = io.BytesIO(data_from_queue)
65-
data = self.buffer.read(size)
66-
self.pos += len(data)
67-
return data
68-
69-
def readinto(self, b):
70-
with memoryview(b) as view, view.cast("B") as byte_view:
71-
data = self.read(len(byte_view))
72-
byte_view[:len(data)] = data
73-
return len(data)
63+
result = self.buffer.readinto(b)
64+
return result
7465

7566
def readable(self) -> bool:
7667
return True

0 commit comments

Comments
 (0)