infra
/
goutils
Archived
1
0
Fork 0

용량 계산 로직 수정

This commit is contained in:
Sangbum Kim 2018-07-06 14:19:56 +09:00
parent f673c30fb4
commit c9fbc24e51
1 changed files with 29 additions and 25 deletions

View File

@ -127,29 +127,30 @@ func FormatInt32(value int32) string { return strconv.FormatInt(int64(value), 10
func FormatInt64(value int64) string { return strconv.FormatInt(value, 10) }
func FormatInt(value int) string { return strconv.FormatInt(int64(value), 10) }
const (
Byte = 1 << (10 * iota)
KiByte
MiByte
GiByte
TiByte
PiByte
EiByte
ZiByte
YiByte
)
var bytesSizeTable = map[string]uint64{
"B": Byte,
"KiB": KiByte,
"MiB": MiByte,
"GiB": GiByte,
"TiB": TiByte,
"PiB": PiByte,
"EiB": EiByte,
"ZiB": ZiByte,
"YiB": YiByte,
var (
sizesIEC = []string{
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB",
"ZiB",
"YiB",
}
sizes = []string{
"B",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB",
}
)
func logn(n, b float64) float64 {
return math.Log(n) / math.Log(b)
@ -171,11 +172,14 @@ func humanateBytes(s uint64, base float64, sizes []string) string {
}
// FileSize calculates the file size and generate user-friendly string.
func FileSize(s uint64) string {
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
return humanateBytes(s, 1024, sizes)
func FileSizeIEC(s uint64) string {
return humanateBytes(s, 1024, sizesIEC)
}
// FileSize calculates the file size and generate user-friendly string.
func FileSize(s uint64) string {
return humanateBytes(s, 1000, sizes)
}
func AspectRatio(srcRect image.Point, toResize uint64) image.Point {
w, h := int(toResize), getRatioSize(int(toResize), srcRect.Y, srcRect.X)
if srcRect.X < srcRect.Y {