diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index 5d52d2d..268247a 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -85,8 +85,8 @@ def bytes_to_readable(size_bytes: int) -> str: Returns: A human-readable string representing the file size. """ - if size_bytes == 0: - return "0B" + if size_bytes < 1024: + return f"{size_bytes} B" size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(math.floor(math.log(size_bytes, 1024))) p = math.pow(1024, i) diff --git a/tests/test_utility.py b/tests/test_utility.py index 1e9012d..6a7c326 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -23,8 +23,8 @@ def test_convert_time_unit(): class TestBytesToReadable: - assert bytes_to_readable(0) == "0B" - assert bytes_to_readable(500) == "500.0 B" + assert bytes_to_readable(0) == "0 B" + assert bytes_to_readable(500) == "500 B" assert bytes_to_readable(1024) == "1.0 KB" assert bytes_to_readable(2048) == "2.0 KB" assert bytes_to_readable(1536) == "1.5 KB" @@ -40,6 +40,7 @@ class TestBytesToReadable: class TestReadableToBytes: def test_conversion(self): + assert readable_to_bytes("0B") == 0 assert readable_to_bytes("100B") == 100 assert readable_to_bytes("50 B") == 50 assert readable_to_bytes("1KB") == 1024