import hashlib


def _compute_file_md5(filename, block_size=2 ** 20):
    """
    Compute the md5 hash of a file, catching any errors.

    Adapted from http://stackoverflow.com/a/1131255/256798

    :param filename:
    :param block_size:
    :return: string version of hash, or empty string if IOError.
    """

    md5 = hashlib.md5()
    try:
        with open(filename, 'rb') as f:
            while True:
                data = f.read(block_size)
                if not data:
                    break
                md5.update(data)
            return md5.hexdigest()
    except IOError as e:
        print('Could not open file: {}'.format(e))
        return ''