- server scripts (e.g. update_versions):

compute MD5 checksums be reading files in pieces instead
    of reading whole file into memory.  From Tolu Aina

svn path=/trunk/boinc/; revision=22743
This commit is contained in:
David Anderson 2010-11-23 22:16:24 +00:00
parent 9838ff4349
commit 9d35970994
2 changed files with 30 additions and 2 deletions

View File

@ -8359,3 +8359,11 @@ David 23 Nov 2010
cpu_sched.cpp
lib/
gui_rpc_client_ops.cpp
David 23 Nov 2010
- server scripts (e.g. update_versions):
compute MD5 checksums be reading files in pieces instead
of reading whole file into memory. From Tolu Aina
py/Boinc/
tools.py

View File

@ -44,8 +44,28 @@ def make_uuid():
return binascii.hexlify(urandom(16))
def md5_file(path):
"""Return a 16-digit MD5 hex digest of a file's contents"""
return md5.new(open(path).read()).hexdigest()
"""
Return a 16-digit MD5 hex digest of a file's contents
Read the file in chunks
"""
chunk = 8096
try:
checksum = md5()
except NameError:
checksum = md5.new()
fp = open(path, 'r')
while True:
buffer = fp.read(chunk)
if not buffer:
break
checksum.update(buffer)
fp.close()
return checksum
def file_size(path):
"""Return the size of a file"""