wrap reader into io.BufferedReader.

PiperOrigin-RevId: 889374560
Change-Id: Ie829d2eb1f06dc024b1848747540b50c11e8d9d6
This commit is contained in:
Akvile Zemgulyte
2026-03-25 12:25:09 -07:00
committed by Copybara-Service
parent 02650a5ded
commit 0f82e0c94c

View File

@@ -110,6 +110,7 @@ class _MultiFileIO(io.RawIOBase):
def close(self):
self._stack.close()
@property
def closed(self) -> bool:
return all(handle.closed for handle in self._handles)
@@ -154,7 +155,8 @@ class _MultiFileIO(io.RawIOBase):
def open_for_reading(model_files: list[pathlib.Path], is_compressed: bool):
with contextlib.closing(_MultiFileIO(model_files)) as f:
if is_compressed:
yield zstandard.ZstdDecompressor().stream_reader(f)
buffered = io.BufferedReader(f)
yield zstandard.ZstdDecompressor().stream_reader(buffered)
else:
yield f