From 7c330500655840fcabbf1c514f710f7ae811e7f6 Mon Sep 17 00:00:00 2001 From: pwhipp Date: Tue, 14 Oct 2014 12:18:00 +1000 Subject: [PATCH] modified sha in the hope that it will use less memory for binary files that lack carriage returns (#180) --- documents/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/documents/models.py b/documents/models.py index 8674679..f4aacd5 100644 --- a/documents/models.py +++ b/documents/models.py @@ -20,8 +20,11 @@ def sha1(f): sha = hashlib.sha1() - for line in f: - sha.update(line) + while True: + chunk = f.read(4096) + if not chunk: + break + sha.update(chunk) return sha.hexdigest()