import hashlib


def md5hash(filename, size=50000):
    """
    Helper function to calculate MD5 hash of the file contents
    (up to a given number of bytes).

    @param filename file path of file to process
    @param size the maximum number of bytes to read
    """
    f = open(filename, 'rb')
    data = f.read(size)
    f.close()
    hash = hashlib.md5(data).hexdigest()
    del data
    return hash