ollama/format/bytes.go

27 lines
546 B
Go
Raw Normal View History

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