format_bytes

Function format_bytes 

Source
pub fn format_bytes(bytes: u64) -> String
Expand description

Converts a file size in bytes into a human-readable format.

This function formats byte sizes dynamically into KB, MB, or GB for readability.

§Conversion Logic:

  • 1,024 bytes → KB
  • 1,024 KB → MB
  • 1,024 MB → GB

§Formatting:

  • Uses two decimal places for precision (e.g., "10.43 MB").
  • If size is below 1 KB, it is displayed in raw bytes (e.g., "512 bytes").

§Parameters:

  • bytes: The size in bytes to format.

§Returns:

  • A String representing the human-readable file size.