From b38809b5d264e223bb1a99a06c1fb72e22ec1b4d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 22 May 2014 18:56:53 -0400 Subject: [PATCH] calculates sha1 checksum in chunks now. fixes #7 --- onionshare.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/onionshare.py b/onionshare.py index aa498e4c..e5e3fa0a 100755 --- a/onionshare.py +++ b/onionshare.py @@ -69,13 +69,15 @@ if __name__ == '__main__': sys.exit('{0} is not a file'.format(filename)) # calculate filehash, file size - sha1 = hashlib.sha1() - f = open(filename, 'rb') - try: - sha1.update(f.read()) - finally: - f.close() - filehash = sha1.hexdigest() + print 'Calculate sha1 checksum' + BLOCKSIZE = 65536 + hasher = hashlib.sha1() + with open(filename, 'rb') as f: + buf = f.read(BLOCKSIZE) + while len(buf) > 0: + hasher.update(buf) + buf = f.read(BLOCKSIZE) + filehash = hasher.hexdigest() filesize = os.path.getsize(filename) # choose a port