From 4f208bade5eeae098d060b59c27b56fd1d569bdd Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 5 Feb 2019 17:19:49 +0100 Subject: move yield_chunks to common.py --- common.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'common.py') diff --git a/common.py b/common.py index bb8b7a4..552b10a 100644 --- a/common.py +++ b/common.py @@ -21,3 +21,12 @@ def decompress_stream(iterable, decompressor): yield data if hasattr(decompressor, "flush"): yield decompressor.flush() + +def yield_chunks(filelike, chunksize=65536): + """Read the given file in chunks of the given size. Returns an itrable + of contents. If the file is binary, it yields bytes, otherwise str.""" + while True: + data = filelike.read(chunksize) + if not data: + break + yield data -- cgit v1.2.3