(bytes: number | string)
| 317 | * @throws {Error} If bytes cannot be converted to a non-negative integer |
| 318 | */ |
| 319 | export function toReadableSizeString(bytes: number | string): string { |
| 320 | const intBytes = parseInt(String(bytes), 10); |
| 321 | if (isNaN(intBytes) || intBytes < 0) { |
| 322 | throw new Error(`Cannot convert '${bytes}' to a readable size format`); |
| 323 | } |
| 324 | if (intBytes >= GiB) { |
| 325 | return `${(intBytes / (GiB * 1.0)).toFixed(2)} GB`; |
| 326 | } else if (intBytes >= MiB) { |
| 327 | return `${(intBytes / (MiB * 1.0)).toFixed(2)} MB`; |
| 328 | } else if (intBytes >= KiB) { |
| 329 | return `${(intBytes / (KiB * 1.0)).toFixed(2)} KB`; |
| 330 | } |
| 331 | return `${intBytes} B`; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Checks whether the given paths refer to the same file system entity (same device and inode). |
no outgoing calls
no test coverage detected