(b int64)
| 52 | } |
| 53 | |
| 54 | func FormatByte(b int64) string { |
| 55 | const ( |
| 56 | KB = 1000 |
| 57 | MB = KB * 1000 |
| 58 | GB = MB * 1000 |
| 59 | TB = GB * 1000 |
| 60 | PB = TB * 1000 |
| 61 | ) |
| 62 | |
| 63 | switch { |
| 64 | case b < KB: |
| 65 | return fmt.Sprintf("%dB", b) |
| 66 | case b < MB: |
| 67 | return fmt.Sprintf("%.1fKB", float64(b)/KB) |
| 68 | case b < GB: |
| 69 | return fmt.Sprintf("%.1fMB", float64(b)/MB) |
| 70 | case b < TB: |
| 71 | return fmt.Sprintf("%.1fGB", float64(b)/GB) |
| 72 | case b < PB: |
| 73 | return fmt.Sprintf("%.1fTB", float64(b)/TB) |
| 74 | default: |
| 75 | return fmt.Sprintf("%.1fPB", float64(b)/PB) |
| 76 | } |
| 77 | } |
no outgoing calls
no test coverage detected