summaryrefslogtreecommitdiff
path: root/dedup/hashing.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2013-07-26 21:53:11 +0200
committerHelmut Grohne <helmut@subdivi.de>2013-07-26 21:53:11 +0200
commit03e7e27b440917081369e797e09de975912cb68c (patch)
tree4d55406f2eb704911c9d7da87dfe84b46d47c0c9 /dedup/hashing.py
parentdc378a18d50142baceaef4c2a416cb5a40f84861 (diff)
downloaddebian-dedup-03e7e27b440917081369e797e09de975912cb68c.tar.gz
verify package hashes when importing via http
Diffstat (limited to 'dedup/hashing.py')
-rw-r--r--dedup/hashing.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/dedup/hashing.py b/dedup/hashing.py
index 1283c7e..002eda8 100644
--- a/dedup/hashing.py
+++ b/dedup/hashing.py
@@ -106,3 +106,22 @@ def hash_file(hashobj, filelike, blocksize=65536):
hashobj.update(data)
data = filelike.read(blocksize)
return hashobj
+
+class HashedStream(object):
+ """A file-like object, that supports sequential reading and hashes the
+ contents on the fly."""
+ def __init__(self, filelike, hashobj):
+ """
+ @param filelike: a file-like object, that must support the read method
+ @param hashobj: a hashlib-like object providing update and hexdigest
+ """
+ self.filelike = filelike
+ self.hashobj = hashobj
+
+ def read(self, length):
+ data = self.filelike.read(length)
+ self.hashobj.update(data)
+ return data
+
+ def hexdigest(self):
+ return self.hashobj.hexdigest()