diff --git a/etiquette/helpers.py b/etiquette/helpers.py index 0db28f0..b10651d 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -4,6 +4,7 @@ codebase but don't deserve to be methods of any class. ''' import datetime +import hashlib import math import mimetypes import os @@ -161,6 +162,15 @@ def get_mimetype(filepath): mimetype = mimetypes.guess_type(filepath)[0] return mimetype +def hash_file(filepath, hasher): + bytestream = read_filebytes(filepath) + for chunk in bytestream: + hasher.update(chunk) + return hasher.hexdigest() + +def hash_file_md5(filepath): + return hash_file(filepath, hasher=hashlib.md5()) + def hyphen_range(s): ''' Given a string like '1-3', return numbers (1, 3) representing lower