From 653c6617323bc6601c071185265a5f8b663e5e3d Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Fri, 15 Apr 2016 09:49:54 +0200 Subject: [PATCH] Read files in chunks Calling `f.read()` would read the entire file at once which is wasteful. It's also not intended given the read loop. Also replace a use of `readline()` with `read(65536)` as well where we want to read the entire file and not only single lines. --- dak/generate_index_diffs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dak/generate_index_diffs.py b/dak/generate_index_diffs.py index 6637c763..485d3770 100755 --- a/dak/generate_index_diffs.py +++ b/dak/generate_index_diffs.py @@ -107,7 +107,7 @@ def smartopen(file): def pipe_file(f, t): f.seek(0) while 1: - l = f.read() + l = f.read(65536) if not l: break t.write(l) t.close() @@ -243,7 +243,7 @@ class Updates: def create_temp_file(r): f = tempfile.TemporaryFile() while 1: - x = r.readline() + x = r.read(65536) if not x: break f.write(x) r.close() -- 2.39.2