diff options
author | Helmut Grohne <helmut@subdivi.de> | 2019-02-05 17:19:49 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2019-02-05 17:19:49 +0100 |
commit | 4f208bade5eeae098d060b59c27b56fd1d569bdd (patch) | |
tree | b9e7ef8888ff937b9b4228a05eff9808a2c1699a /common.py | |
parent | a3cc49725febb2cca1c915ef768604831563954f (diff) | |
download | crossqa-4f208bade5eeae098d060b59c27b56fd1d569bdd.tar.gz |
move yield_chunks to common.py
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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 |