diff --git a/src/hashtree.py b/src/hashtree.py --- a/src/hashtree.py +++ b/src/hashtree.py @@ -1,6 +1,8 @@ import hashlib import os +from util import progress + class HashTree: HASH_LEN=16 # bytes @@ -20,10 +22,13 @@ class HashTree: size=stat.st_size # !! symlinks leafCount=(size-1)//HashTree.BLOCK_SIZE+1 # number of leaf blocks res=cls(leafCount) + print("hashing file:") for i in range(leafCount): data=f.read(HashTree.BLOCK_SIZE) res.insertLeaf(hashlib.sha256(data).digest()[HashTree.HASH_LEN:]) + + progress(i, leafCount) res.buildTree() return res @@ -68,8 +73,10 @@ class HashTree: ## Fast construction of the tree over the leaves. O(n). def buildTree(self): + print("building tree:") 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) if __name__=="__main__":