import logging


def byte_per_second(nbytes=None, suffix="B/s"):
    """Human readable bytes per second sizes.

    Args:
        nbytes (float): The number of bytes per second.
        suffix (str, optional): The suffix of bytes per second in inputted
            number.

    Returns:
        String: The best readable byte per second size.
    """
    if nbytes is None:
        return None

    try:
        suffixes = ["B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s"]
        index = 0

        if suffixes.index(suffix) >= 0:
            value = nbytes * (1024.0**suffixes.index(suffix))
        else:
            value = nbytes

        while value >= 1024.0 and index < len(suffixes) - 1:
            value /= 1024.0
            index += 1
        temp = "{:.2f}".format(value).rstrip("0").rstrip(".")
        return "{} {}".format(temp, suffixes[index])
    except IOError as err:
        logging.error(err)