Skip to content

download_utils

bar_progress(current, total, width=80)

Display a progress bar for a download.

Parameters:

Name Type Description Default
current int

The current progress value.

required
total int

The total progress value.

required
width int

The width of the progress bar in characters. Defaults to 80.

80

Returns:

Type Description

None

Source code in fmcib/utils/download_utils.py
def bar_progress(current, total, width=80):
    """
    Display a progress bar for a download.

    Args:
        current (int): The current progress value.
        total (int): The total progress value.
        width (int, optional): The width of the progress bar in characters. Defaults to 80.

    Raises:
        None

    Returns:
        None
    """
    progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total)
    # Don't use print() as it will print in new line every time.
    sys.stdout.write("\r" + progress_message)
    sys.stdout.flush()