Skip to main content

Module common

Module common 

Source
Expand description

Common shared utilities used across download, upload, formatting, and progress modules.

This module consolidates duplicated functionality to follow DRY principles:

  • Bandwidth calculation
  • Stream count determination
  • Distance formatting
  • Data size formatting
  • Terminal width detection

Functionsยง

bar_chart
Render a horizontal bar chart using Unicode block characters.
calculate_bandwidth
Calculate bandwidth in bits per second from bytes transferred and elapsed time.
determine_stream_countDeprecated
Determine number of concurrent streams based on single connection flag.
format_data_size
Format byte count into a human-readable string (KB, MB, GB).
format_data_size_tabular
Format data size (bytes) with tabular alignment for data transfer amounts. Returns a fixed-width string like " 15.0 MB".
format_distance
Format distance consistently: 1 decimal for < 100 km, 0 decimals for >= 100 km.
format_duration_tabular
Format duration with tabular alignment.
format_jitter_tabular
Format jitter in ms with tabular alignment.
format_latency_tabular
Format latency in ms with tabular alignment. Returns a fixed-width string like " 12.1 ms".
format_loss_tabular
Format packet loss percentage with tabular alignment.
format_speed_tabular
Format a speed value in Mbps with tabular alignment. Returns a fixed-width string like " 150.00 Mb/s" or " 0.12 Gb/s".
get_terminal_width
Get the terminal width in columns, or a sensible default.
get_terminal_width_bounded
Get the terminal width with a minimum and maximum bound.
is_valid_ipv4
Validate an IPv4 address string.
tabular_number
Format a numeric value with fixed-width padding for vertical alignment. Pads with leading spaces so numbers right-align in columns.