calculates sha1 checksum in chunks now. fixes #7

This commit is contained in:
Micah Lee 2014-05-22 18:56:53 -04:00
parent 99c444dc4d
commit b38809b5d2

View File

@ -69,13 +69,15 @@ if __name__ == '__main__':
sys.exit('{0} is not a file'.format(filename)) sys.exit('{0} is not a file'.format(filename))
# calculate filehash, file size # calculate filehash, file size
sha1 = hashlib.sha1() print 'Calculate sha1 checksum'
f = open(filename, 'rb') BLOCKSIZE = 65536
try: hasher = hashlib.sha1()
sha1.update(f.read()) with open(filename, 'rb') as f:
finally: buf = f.read(BLOCKSIZE)
f.close() while len(buf) > 0:
filehash = sha1.hexdigest() hasher.update(buf)
buf = f.read(BLOCKSIZE)
filehash = hasher.hexdigest()
filesize = os.path.getsize(filename) filesize = os.path.getsize(filename)
# choose a port # choose a port