From c9fbc24e51208f426bcef4af484c9f48373b65d7 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Fri, 6 Jul 2018 14:19:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9A=A9=EB=9F=89=20=EA=B3=84=EC=82=B0=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- misc/converse.go | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/misc/converse.go b/misc/converse.go index b95b18a..2f8f8a0 100644 --- a/misc/converse.go +++ b/misc/converse.go @@ -127,30 +127,31 @@ 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 ( + sizesIEC = []string{ + "B", + "KiB", + "MiB", + "GiB", + "TiB", + "PiB", + "EiB", + "ZiB", + "YiB", + } + sizes = []string{ + "B", + "KB", + "MB", + "GB", + "TB", + "PB", + "EB", + "ZB", + "YB", + } ) -var bytesSizeTable = map[string]uint64{ - "B": Byte, - "KiB": KiByte, - "MiB": MiByte, - "GiB": GiByte, - "TiB": TiByte, - "PiB": PiByte, - "EiB": EiByte, - "ZiB": ZiByte, - "YiB": YiByte, -} - 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 {