From 03c267e5c919041899ac95ed637a18faff111489 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 24 Nov 2022 17:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=8E=B7=E5=8F=96=E5=A4=B1=E8=B4=A5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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