import base64


def file2base64(path: str, batch_byte=4096):
    """
    A base64 hash function that have the ability to prevented memory overflow.

    :param path: the path of file
    :param batch_byte: the size of every batch
    :return: base64 bytes result
    """

    base64_list = bytes()
    with open(path, 'rb') as f:
        while True:
            data = f.read(batch_byte)
            if not data:
                break
            base64_list += base64.b64encode(data)

    return base64_list