from typing import Optional
from typing import Union


def __parse_file_size(file_size: Optional[Union[int, str]]) -> int:
    """
    Parse file size, that can be just integer for bytes, or have suffixes
    like b, k, m, g.
    """
    if file_size is None:
        return 1 * 1024 * 1024

    if isinstance(file_size, int):
        return file_size

    suffixes = {"b": 1, "k": 2 ** 10, "m": 2 ** 20, "g": 2 ** 30}

    # get numbers in from
    num = ""
    multiplier = 1
    for s in file_size:
        if s.isdigit():
            num += s
        elif s in suffixes and len(num) > 0:
            multiplier = suffixes[s]
        else:
            raise ValueError(f"file size {file_size} not supported")

    return int(num) * multiplier