parse_bytes#

bayesflow.utils.parse_bytes(s: str) int[source]#

Parse a string in the format ‘{value} {prefix}{unit}’ and return the number of bytes, flooring to the nearest integer.

The parsing is case-sensitive. E.g., uppercase ‘K’ will not be recognized as ‘kilo’, and lowercase ‘b’ will be recognized as ‘bit’ rather than ‘byte’.

Examples:
>>> parse_bytes("8 GB")  # 8 Gigabyte
8000000000
>>> parse_bytes("32 kiB")  # 32 Kibibyte
32768
>>> parse_bytes("1 Tb")  # 1 Terrabit
125000000000
>>> parse_bytes("2.5 kB")  # 2.5 Kilobyte
2500
>>> parse_bytes("1e9 B")  # 10^9 Bytes
1000000000