summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-02-19 22:05:54 +0100
committerHelmut Grohne <helmut@subdivi.de>2021-02-19 22:05:54 +0100
commitdfcfa63fd6b4269ea4ddf57c943258d1560ad2a4 (patch)
treeda11fb3c78461f24a4ec1127068a7464ca4d5a6d
parent27cd6b51471a3a14cdaf20aade95ef72339c1b40 (diff)
downloadcrossqa-dfcfa63fd6b4269ea4ddf57c943258d1560ad2a4.tar.gz
simplify common functions
-rw-r--r--common.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/common.py b/common.py
index 3b106b6..1d32d10 100644
--- a/common.py
+++ b/common.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+
+import functools
import typing
ByteIterable = typing.Iterable[bytes]
@@ -22,17 +23,11 @@ def decompress_stream(iterable: ByteIterable, decompressor) -> ByteIterable:
"""Decompress an iterable of bytes using the given decompressor into
another (decompressed) iterable of bytes. The decompressor can be a
bz2.BZ2Decompressor or lzma.LZMADecompressor instance."""
- for data in iterable:
- data = decompressor.decompress(data)
- yield data
+ yield from map(decompressor.decompress, iterable)
if hasattr(decompressor, "flush"):
yield decompressor.flush()
def yield_chunks(filelike, chunksize=65536) -> ByteIterable:
"""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
+ return iter(functools.partial(filelike.read, chunksize), b"")