-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Dan Gottlieb <[email protected]> Co-authored-by: Sagie Maoz <[email protected]>
- Loading branch information
1 parent
7a0577c
commit ea997e0
Showing
47 changed files
with
6,540 additions
and
3,457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package data | ||
|
||
import "fmt" | ||
|
||
const ( | ||
_ = 1 << (10 * iota) | ||
kib | ||
mib | ||
gib | ||
tib | ||
) | ||
|
||
// FormatBytesI64 formats an int64 representing bytes | ||
// as an easily human parsable string. | ||
func FormatBytesI64(b int64) string { | ||
switch { | ||
case b > tib: | ||
return fmt.Sprintf("%.2f TB", float64(b)/tib) | ||
case b > gib: | ||
return fmt.Sprintf("%.2f GB", float64(b)/gib) | ||
case b > mib: | ||
return fmt.Sprintf("%.2f MB", float64(b)/mib) | ||
case b > kib: | ||
return fmt.Sprintf("%.2f KB", float64(b)/kib) | ||
default: | ||
return fmt.Sprintf("%d Bytes", b) | ||
} | ||
} | ||
|
||
// FormatBytesU64 formats an uint64 representing bytes | ||
// as an easily human parsable string. | ||
func FormatBytesU64(b uint64) string { | ||
switch { | ||
case b > tib: | ||
return fmt.Sprintf("%.2f TB", float64(b)/tib) | ||
case b > gib: | ||
return fmt.Sprintf("%.2f GB", float64(b)/gib) | ||
case b > mib: | ||
return fmt.Sprintf("%.2f MB", float64(b)/mib) | ||
case b > kib: | ||
return fmt.Sprintf("%.2f KB", float64(b)/kib) | ||
default: | ||
return fmt.Sprintf("%d Bytes", b) | ||
} | ||
} |
Oops, something went wrong.