diff --git a/src/hashtree.py b/src/hashtree.py --- a/src/hashtree.py +++ b/src/hashtree.py @@ -2,7 +2,7 @@ import os from datetime import datetime -from util import progress +from util import Progress class HashTree: @@ -25,12 +25,13 @@ class HashTree: res=cls(leafCount) print(datetime.now(), "hashing file:") + progress=Progress(leafCount) for i in range(leafCount): data=f.read(HashTree.BLOCK_SIZE) res.insertLeaf(hashlib.sha256(data).digest()[HashTree.HASH_LEN:]) - progress(i, leafCount) - print("100%") + progress.p(i) + progress.done() res.buildTree() return res @@ -76,10 +77,11 @@ class HashTree: ## Fast construction of the tree over the leaves. O(n). def buildTree(self): print(datetime.now(), "building tree:") + progress=Progress(-1, self.leafStart-1) for i in range(self.leafStart-1,-1,-1): self.store[i]=hashlib.sha256(self.store[i*2+1]+self.store[i*2+2]).digest()[HashTree.HASH_LEN:] - progress(i, -1, self.leafStart - 1) - print() + progress.p(i) + progress.done() if __name__=="__main__":