@@ -13,6 +13,8 @@ var (
func BinaryPrefix(on bool) {
if on {
sfx = "iB"
+ } else {
+ sfx = "B"
}
@@ -21,9 +23,7 @@ func Format(b uint64) string {
n := float64(b)
unit := float64(1024)
- if n == 0 {
- return "--"
- } else if n < unit {
+ if n < unit {
return fmt.Sprintf("%.0f B", n)
} else {
e := math.Floor(math.Log(n) / math.Log(unit))
@@ -1,21 +1,10 @@
package bytes
-import (
- "testing"
- "github.com/labstack/gommon/bytes"
- "fmt"
-)
+import "testing"
func TestFormat(t *testing.T) {
- fmt.Println(bytes.Format(1323))
- // Zero
- f := Format(0)
- if f != "--" {
- t.Errorf("formatted bytes should be --, found %s", f)
- }
-
// B
- f = Format(515)
+ f := Format(515)
if f != "515 B" {
t.Errorf("formatted bytes should be 515 B, found %s", f)