def calculate_checksum_on_stream(
    f,
    algorithm=d1_common.const.DEFAULT_CHECKSUM_ALGORITHM,
    chunk_size=DEFAULT_CHUNK_SIZE,
):
    """Calculate the checksum of a stream.

    Args:
      f: file-like object
        Only requirement is a ``read()`` method that returns ``bytes``.

      algorithm: str
        Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``.

      chunk_size : int
        Number of bytes to read from the file and add to the checksum at a time.

    Returns:
      str : Checksum as a hexadecimal string, with length decided by the algorithm.

    """
    checksum_calc = get_checksum_calculator_by_dataone_designator(algorithm)
    while True:
        chunk = f.read(chunk_size)
        if not chunk:
            break
        checksum_calc.update(chunk)
    return checksum_calc.hexdigest()
Calculate the checksum of a stream.

    Args:
      f: file-like object
        Only requirement is a ``read()`` method that returns ``bytes``.

      algorithm: str
        Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``.

      chunk_size : int
        Number of bytes to read from the file and add to the checksum at a time.

    Returns:
      str : Checksum as a hexadecimal string, with length decided by the algorithm.