MCPcopy Create free account
hub / github.com/MCSLTeam/MCSL2 / getReadableSize

Function getReadableSize

MCSL2Lib/ProgramControllers/downloadController.py:44–53  ·  view source on GitHub ↗

将字节数转换为可读的大小格式

(size_bytes)

Source from the content-addressed store, hash-verified

42
43
44def getReadableSize(size_bytes):
45 """将字节数转换为可读的大小格式"""
46 if size_bytes == 0:
47 return "0B"
48 size_names = ["B", "KB", "MB", "GB", "TB"]
49 i = 0
50 while size_bytes >= 1024 and i < len(size_names) - 1:
51 size_bytes /= 1024.0
52 i += 1
53 return f"{size_bytes:.1f}{size_names[i]}"
54
55
56def getReadableSpeed(speed_bytes_per_sec):

Callers 4

_emit_download_infoMethod · 0.85
_emit_speed_infoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected