diff options
author | Max Kellermann <max@musicpd.org> | 2016-12-29 21:23:54 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2016-12-29 21:33:12 +0100 |
commit | 8bfabbe265c58a99d0eb80faa102940d6e59be72 (patch) | |
tree | f954e274255e30b0cb91585997f9b3518b19612e /python/build/verify.py | |
parent | e334b16aaa13eaf1c7ad29388ab109cf8aecb324 (diff) |
python/build/verify: move code to feed_file()
Diffstat (limited to 'python/build/verify.py')
-rw-r--r-- | python/build/verify.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/python/build/verify.py b/python/build/verify.py index 8ec190cac..9b7aa911d 100644 --- a/python/build/verify.py +++ b/python/build/verify.py @@ -1,13 +1,24 @@ import hashlib +def feed_file(h, f): + """Feed data read from an open file into the hashlib instance.""" + + while True: + data = f.read(65536) + if len(data) == 0: + # end of file + break + h.update(data) + +def feed_file_path(h, path): + """Feed data read from a file (to be opened by this function) into the hashlib instance.""" + + with open(path, 'rb') as f: + feed_file(h, f) + def file_md5(path): """Calculate the MD5 checksum of a file and return it in hexadecimal notation.""" - with open(path, 'rb') as f: - m = hashlib.md5() - while True: - data = f.read(65536) - if len(data) == 0: - # end of file - return m.hexdigest() - m.update(data) + h = hashlib.md5() + feed_file_path(h, path) + return h.hexdigest() |