hbutils.scale.size¶
- Overview:
Useful utilities for memory size units, such as MB/KB/B.
size_to_bytes¶
-
hbutils.scale.size.
size_to_bytes
(size: Union[int, float, str, bitmath.Byte]) → int[source]¶ - Overview:
Turn any types of memory size to integer value in bytes.
- Arguments:
size (
Union[int, float, str, Byte]
): Any types of size information.
- Returns:
bytes (
int
): Int formatted size in bytes.
- Examples::
>>> from hbutils.scale import size_to_bytes >>> size_to_bytes(23344) 23344 >>> size_to_bytes('23356 KB') 23356000 >>> size_to_bytes('3.54 GB') 3540000000 >>> size_to_bytes('3.54 GiB') __main__:1: UserWarning: Float detected in variable in bytes (3801046056.96), rounded integer value (3801046057) is used. 3801046057
size_to_bytes_str¶
-
hbutils.scale.size.
size_to_bytes_str
(size: Union[int, float, str, bitmath.Byte]) → str[source]¶ - Overview:
Turn any types of memory size to string value in the best unit.
- Arguments:
size (
Union[int, float, str, Byte]
): Any types of size information.
- Returns:
bytes (
int
): String formatted size value in the best unit.
- Examples::
>>> from hbutils.scale import size_to_bytes_str >>> size_to_bytes_str(23344) '22.796875 KiB' >>> size_to_bytes_str('23356 KB') '22.274017333984375 MiB' >>> size_to_bytes_str('3.54 GB') '3.296881914138794 GiB' >>> size_to_bytes_str('3.54 GiB') __main__:1: UserWarning: Float detected in variable in bytes (3801046056.96), rounded integer value (3801046057) is used. '3.540000000037253 GiB'