Skip to content

Commit

Permalink
[DATA-2672] Refactor data capture and data sync (#4161)
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
3 people authored Sep 26, 2024
1 parent 7a0577c commit ea997e0
Show file tree
Hide file tree
Showing 47 changed files with 6,540 additions and 3,457 deletions.
45 changes: 45 additions & 0 deletions data/bytes_format_utils.go
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)
}
}
Loading

0 comments on commit ea997e0

Please sign in to comment.