(text: str)
| 11 | |
| 12 | |
| 13 | def _str2bytes(text: str) -> int: |
| 14 | regex = re.compile(r"(\d+(?:\.\d+)?)\s*([kmg]?b)", re.IGNORECASE) |
| 15 | order = ["b", "kb", "mb", "gb"] |
| 16 | result = regex.findall(text) |
| 17 | if len(result) != 1: |
| 18 | raise ValueError( |
| 19 | "Formatting of `value` only supports bytes(B), kilobyte(KB), megabyte(MB) and gigabyte(GB) units" |
| 20 | ) |
| 21 | return int(float(result[0][0]) * 1024 ** order.index(result[0][1].lower())) |
| 22 | |
| 23 | |
| 24 | @property |
no test coverage detected