move yield_chunks to common.py
authorHelmut Grohne <helmut@subdivi.de>
Tue, 5 Feb 2019 16:19:49 +0000 (17:19 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Tue, 5 Feb 2019 16:19:49 +0000 (17:19 +0100)
build.py
common.py

index c0def3b..37a585a 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -8,14 +8,7 @@ import os.path
 import sqlite3
 import subprocess
 
-from common import decompress_stream, yield_lines
-
-def yield_chunks(filelike, chunksize=65536):
-    while True:
-        data = filelike.read(chunksize)
-        if not data:
-            break
-        yield data
+from common import decompress_stream, yield_lines, yield_chunks
 
 def scan_log_status(filelike):
     it = yield_chunks(filelike)
index bb8b7a4..552b10a 100644 (file)
--- 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