import binascii


def base64(data):
    """
    Get base64 string (1 line) from binary "data".

    :param (bytes, bytearray) data: Data to format.
    :raises TypeError: Raises an error if the data is not a bytearray of bytes
        instance
    :return str: Empty string if this failed, otherwise the base64 encoded
        string.
    """
    if isinstance(data, (bytearray, bytes)):
        b64_data = binascii.b2a_base64(data).decode('ascii')
    else:
        raise TypeError('Data passed to base64 function is of the wrong type')

    # Remove any new lines and carriage returns
    b64_data.replace("\n", "").replace("\r", "")
    return b64_data.strip("\n")