ollama/format/bytes.go

24 lines
445 B
Go
Raw Normal View History

2023-10-11 17:55:07 +00:00
package format
import "fmt"
2023-10-12 16:34:16 +00:00
const (
Byte = 1
KiloByte = Byte * 1000
MegaByte = KiloByte * 1000
GigaByte = MegaByte * 1000
)
2023-10-11 17:55:07 +00:00
func HumanBytes(b int64) string {
switch {
2023-10-12 16:34:16 +00:00
case b > GigaByte:
return fmt.Sprintf("%.1f GB", float64(b)/GigaByte)
2023-10-12 16:34:16 +00:00
case b > MegaByte:
return fmt.Sprintf("%.1f MB", float64(b)/MegaByte)
2023-10-12 16:34:16 +00:00
case b > KiloByte:
return fmt.Sprintf("%.1f KB", float64(b)/KiloByte)
2023-10-11 17:55:07 +00:00
default:
return fmt.Sprintf("%d B", b)
}
}