import hashlib


def md5_from_filelike(filelike, block_size_factor=128):
    """Create the hexdigested md5 checksum of the contents from a filelike object.

    :param filelike: the filelike object for whose contents to generate the md5 checksum
    :param block_size_factor: the file is read at chunks of size ``block_size_factor * md5.block_size``, where
        ``md5.block_size`` is the block_size used internally by the hashlib module.
    :returns: a string with the hexdigest md5.
    :raises: no checks are done on the filelike object, so it may raise IOError if it cannot be read from.
    """
    md5 = hashlib.md5()

    # I read 128 bytes at a time until it returns the empty string b''
    for chunk in iter(lambda: filelike.read(block_size_factor * md5.block_size), b''):
        md5.update(chunk)

    return md5.hexdigest()