diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hash.cpp | 8 | ||||
-rw-r--r-- | src/hash.h | 4 | ||||
-rw-r--r-- | src/wrapper.cpp | 2 |
3 files changed, 13 insertions, 1 deletions
diff --git a/src/hash.cpp b/src/hash.cpp index 89b14cc..82df4c0 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -60,4 +60,12 @@ namespace Multihash { std::string Hash::hash_digest() { throw std::runtime_error("Not implemented."); } + + void _hash_file(int fileno, Hash* hash) { + char buf[32768]; + int s; + while((s = read(fileno, buf, 32768)) > 0) { + hash->_update(buf, s); + } + } } @@ -13,15 +13,17 @@ namespace Multihash { private: std::string digest_str; Hash* next; - void _update(const char* data, int length); protected: virtual void hash_update(const char* data, int length); virtual std::string hash_digest(); public: Hash(Hash* n = 0); void update(std::string data); + void _update(const char* data, int length); std::string digest(); }; + + void _hash_file(int fileno, Hash* hash); } #endif // _HASH_H_ diff --git a/src/wrapper.cpp b/src/wrapper.cpp index cbe86f5..a93dae2 100644 --- a/src/wrapper.cpp +++ b/src/wrapper.cpp @@ -26,4 +26,6 @@ BOOST_PYTHON_MODULE(_multihash) class_<Multihash::SHA1, bases<Hash> >("SHA1") .def(init<optional<Hash*> >()); + + def("_hash_file", Multihash::_hash_file); } |