summaryrefslogtreecommitdiff
path: root/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'common.py')
-rw-r--r--common.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/common.py b/common.py
index 552b10a..ef146c0 100644
--- a/common.py
+++ b/common.py
@@ -1,4 +1,8 @@
-def yield_lines(iterable):
+import typing
+
+ByteIterable = typing.Iterable[bytes]
+
+def yield_lines(iterable: ByteIterable) -> ByteIterable:
"""Converts an arbitrary bytes iterable into an iterable that yields whole
lines. The final byte of each returned value (except possibly the last one)
is a newline or carriage return character. The concatenation of the input
@@ -12,7 +16,7 @@ def yield_lines(iterable):
if buff:
yield buff
-def decompress_stream(iterable, decompressor):
+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."""
@@ -22,7 +26,7 @@ def decompress_stream(iterable, decompressor):
if hasattr(decompressor, "flush"):
yield decompressor.flush()
-def yield_chunks(filelike, chunksize=65536):
+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: