diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index 1e4c037..fe6b41f 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -57,6 +57,8 @@ class FileSizeConvert: @staticmethod def parse_2_byte(file_size: str): + if not file_size: + return 0 """将文件大小字符串解析为字节""" regex = re.compile(r'(\d+(?:\.\d+)?)\s*([kmgtp]?b)', re.IGNORECASE) @@ -67,11 +69,13 @@ class FileSizeConvert: @staticmethod def parse_2_file_size(byte: int): + if not byte: + return '0B' units = ["B", "KB", "MB", "GB", "TB", "PB", 'EB'] size = 1024.0 for i in range(len(units)): if (byte / size) < 1: - return "%.3f%s" % (byte, units[i]) + return "%.3f %s" % (byte, units[i]) byte = byte / size