Convert a filesize in to a string (powers of 1000, SI prefixes). In this convention, ``1000 B = 1 kB``. This is typically the format used to advertise the storage capacity of USB flash drives and the like (*256 MB* meaning actually a storage capacity of more than *256 000 000 B*),
(
size: int,
*,
precision: Optional[int] = 1,
separator: Optional[str] = " ",
)
| 50 | |
| 51 | |
| 52 | def decimal( |
| 53 | size: int, |
| 54 | *, |
| 55 | precision: Optional[int] = 1, |
| 56 | separator: Optional[str] = " ", |
| 57 | ) -> str: |
| 58 | """Convert a filesize in to a string (powers of 1000, SI prefixes). |
| 59 | |
| 60 | In this convention, ``1000 B = 1 kB``. |
| 61 | |
| 62 | This is typically the format used to advertise the storage |
| 63 | capacity of USB flash drives and the like (*256 MB* meaning |
| 64 | actually a storage capacity of more than *256 000 000 B*), |
| 65 | or used by **Mac OS X** since v10.6 to report file sizes. |
| 66 | |
| 67 | Arguments: |
| 68 | int (size): A file size. |
| 69 | int (precision): The number of decimal places to include (default = 1). |
| 70 | str (separator): The string to separate the value from the units (default = " "). |
| 71 | |
| 72 | Returns: |
| 73 | `str`: A string containing a abbreviated file size and units. |
| 74 | |
| 75 | Example: |
| 76 | >>> filesize.decimal(30000) |
| 77 | '30.0 kB' |
| 78 | >>> filesize.decimal(30000, precision=2, separator="") |
| 79 | '30.00kB' |
| 80 | |
| 81 | """ |
| 82 | return _to_str( |
| 83 | size, |
| 84 | ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"), |
| 85 | 1000, |
| 86 | precision=precision, |
| 87 | separator=separator, |
| 88 | ) |
no test coverage detected
searching dependent graphs…