(bytes: number)
| 29 | const MIN_ELAPSED_SECONDS = 0.001 |
| 30 | |
| 31 | export const formatBytes = (bytes: number): string => { |
| 32 | const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'] |
| 33 | |
| 34 | if (!Number.isFinite(bytes) || bytes <= 0) { |
| 35 | return '0 B' |
| 36 | } |
| 37 | |
| 38 | let unitIndex = 0 |
| 39 | let value = bytes |
| 40 | |
| 41 | while (value >= 1024 && unitIndex < units.length - 1) { |
| 42 | value /= 1024 |
| 43 | unitIndex += 1 |
| 44 | } |
| 45 | |
| 46 | const rounded = Math.round(value * 100) / 100 |
| 47 | const formatted = String(rounded) |
| 48 | |
| 49 | return `${formatted} ${units[unitIndex]}` |
| 50 | } |
| 51 | |
| 52 | export const formatCompressionDelta = (rawBytes: number, outputBytes: number): string | undefined => { |
| 53 | if (rawBytes <= 0) { |
no outgoing calls
no test coverage detected