diff options
author | Helmut Grohne <helmut@subdivi.de> | 2013-08-02 08:40:49 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2013-08-02 08:40:49 +0200 |
commit | cb3708825bf7ea32314040575cef35980dad0cd8 (patch) | |
tree | 31575a8525dc90ba6904268d94f47e1604bf0557 /dedup/hashing.py | |
parent | a4bbbb6e664e605634cb3f9e0564c7e4a93697be (diff) | |
parent | 2712edb550968ce7ec8cd9800241d7944666631a (diff) | |
download | debian-dedup-cb3708825bf7ea32314040575cef35980dad0cd8.tar.gz |
Merge branch master into sqlalchemy
This makes the sqlalchemy branch schema-compatible with master again.
The biggest change on master was the introduction of the function table.
It caused most of the conflicts. Note that webapp had one conflict not
detected by git: The selecting of issues in show_package needed
sqlalchemy conversion.
Conflicts:
README
update_sharing.py
webapp.py
Diffstat (limited to 'dedup/hashing.py')
-rw-r--r-- | dedup/hashing.py | 19 |
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() |