Unverified Commit 9fa88172 authored by Mario Šaško's avatar Mario Šaško Committed by GitHub
Browse files

Minor fixes/improvements in `convert_file_size_to_int` (#16891)

* Minor improvements to `convert_file_size_to_int`

* Add <unit>bit version to kilos and megas

* Minor fix
parent 6d90d76f
...@@ -145,7 +145,7 @@ def convert_file_size_to_int(size: Union[int, str]): ...@@ -145,7 +145,7 @@ def convert_file_size_to_int(size: Union[int, str]):
Example: Example:
```py ```py
>>> convert_file_size_to_int("1MB") >>> convert_file_size_to_int("1MiB")
1048576 1048576
``` ```
""" """
...@@ -158,11 +158,14 @@ def convert_file_size_to_int(size: Union[int, str]): ...@@ -158,11 +158,14 @@ def convert_file_size_to_int(size: Union[int, str]):
if size.upper().endswith("KIB"): if size.upper().endswith("KIB"):
return int(size[:-3]) * (2**10) return int(size[:-3]) * (2**10)
if size.upper().endswith("GB"): if size.upper().endswith("GB"):
return int(size[:-2]) * (10**9) int_size = int(size[:-2]) * (10**9)
return int_size // 8 if size.endswith("b") else int_size
if size.upper().endswith("MB"): if size.upper().endswith("MB"):
return int(size[:-2]) * (10**6) int_size = int(size[:-2]) * (10**6)
return int_size // 8 if size.endswith("b") else int_size
if size.upper().endswith("KB"): if size.upper().endswith("KB"):
return int(size[:-2]) * (10**3) int_size = int(size[:-2]) * (10**3)
return int_size // 8 if size.endswith("b") else int_size
raise ValueError("`size` is not in a valid format. Use an integer followed by the unit, e.g., '5GB'.") raise ValueError("`size` is not in a valid format. Use an integer followed by the unit, e.g., '5GB'.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment