MCPcopy
hub / github.com/mandarons/icloud-docker / format_bytes

Function format_bytes

src/sync_stats.py:117–137  ·  view source on GitHub ↗

Format byte count as human-readable string. Args: bytes_count: Number of bytes Returns: Formatted string (e.g., "1.5 GB", "234 MB")

(bytes_count: int)

Source from the content-addressed store, hash-verified

115
116
117def format_bytes(bytes_count: int) -> str:
118 """Format byte count as human-readable string.
119
120 Args:
121 bytes_count: Number of bytes
122
123 Returns:
124 Formatted string (e.g., "1.5 GB", "234 MB")
125 """
126 if bytes_count == 0:
127 return "0 B"
128
129 units = ["B", "KB", "MB", "GB", "TB"]
130 unit_index = 0
131 size = float(bytes_count)
132
133 while size >= 1024.0 and unit_index < len(units) - 1:
134 size /= 1024.0
135 unit_index += 1
136
137 return f"{size:.1f} {units[unit_index]}"
138
139
140def format_duration(seconds: float) -> str:

Callers 2

test_format_bytesMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_format_bytesMethod · 0.72