import base64


def read_file_as_b64(image_path):
    """
    Encode image file or image from zip archive to base64

    Args:
        image_path (bytes or str): if from a zip archive, it is an image in
                                   bytes;
                                   if from local directory, it should be a
                                   string specifying the filepath

    Returns:
        b64_string (str): encoded image file ready to be sent to server
    """
    # If input is from zip archive, it will be in bytes
    if type(image_path) is bytes:
        b64_bytes = base64.b64encode(image_path)
    else:  # Or it is from a directory
        with open(image_path, "rb") as image_file:
            b64_bytes = base64.b64encode(image_file.read())
    b64_string = str(b64_bytes, encoding='utf-8')

    return b64_string