unit.py 414 B

12345678910111213141516171819
  1. BYTES_TO_KIB = 1024
  2. BYTES_TO_MIB = 1024 * 1024
  3. BYTES_TO_GIB = 1024 * 1024 * 1024
  4. def byte_to_unit(byte: int, unit: int) -> float:
  5. return round(byte / unit, 2)
  6. def byte_to_kib(byte: int) -> float:
  7. return byte_to_unit(byte, BYTES_TO_KIB)
  8. def byte_to_mib(byte: int) -> float:
  9. return byte_to_unit(byte, BYTES_TO_MIB)
  10. def byte_to_gib(byte: int) -> float:
  11. return byte_to_unit(byte, BYTES_TO_GIB)