# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/fastdotcom/megabytes.patch # Copyright (C) 2025 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- Patched the code to show MegaBytes by default instead of whatever unit in Bits. - NoTag diff --git a/fast.go b/fast.go index ed83a32..ed08232 100644 --- a/fast.go +++ b/fast.go @@ -11,10 +11,11 @@ import ( ) func main() { - var kb, mb, gb, silent bool + var kb, mb, gb, mB, silent bool flag.BoolVar(&kb, "k", false, "Format output in Kbps") flag.BoolVar(&mb, "m", false, "Format output in Mbps") flag.BoolVar(&gb, "g", false, "Format output in Gbps") + flag.BoolVar(&mB, "mB", true, "Format output in MB/s") // Choose MB by default flag.BoolVar(&silent, "silent", false, "Surpress all output except for the final result") flag.Parse() @@ -64,14 +65,8 @@ func main() { go func() { var value, units string for Kbps := range KbpsChan { - value, units = format(Kbps, kb, mb, gb) - // don't print the units of measurement if explicitly asked for - if kb || mb || gb { - status = fmt.Sprintf("%s", value) - } else { - status = fmt.Sprintf("%s %s", value, units) - } - + value, units = format(Kbps, kb, mb, mB, gb) + status = fmt.Sprintf("%s %s", value, units) } if silent { fmt.Printf("%s\n", status) @@ -102,6 +97,12 @@ func formatMbps(Kbps float64) (string, string, float64) { value := Kbps / 1000 return f, unit, value } +func formatMBps(Kbps float64) (string, string, float64) { + f := "%.2f" + unit := "MB/s" + value := Kbps / 1000 / 8 + return f, unit, value +} func formatKbps(Kbps float64) (string, string, float64) { f := "%.f" unit := "Kbps" @@ -109,7 +110,7 @@ func formatKbps(Kbps float64) (string, string, float64) { return f, unit, value } -func format(Kbps float64, kb bool, mb bool, gb bool) (string, string) { +func format(Kbps float64, kb bool, mb bool, mB bool, gb bool) (string, string) { var value float64 var unit string var f string @@ -118,6 +119,8 @@ func format(Kbps float64, kb bool, mb bool, gb bool) (string, string) { f, unit, value = formatKbps(Kbps) } else if mb { f, unit, value = formatMbps(Kbps) + } else if mB { + f, unit, value = formatMBps(Kbps) } else if gb { f, unit, value = formatGbps(Kbps) } else if Kbps > 1000000 { // Gbps