1
0

In ConvertFileSize code was cosmetically changed a little.

This commit is contained in:
Alexander Andreev 2023-05-26 17:23:09 +04:00
parent 54f87951c1
commit d94030a4e8
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -1,8 +1,7 @@
package utils package utils
import ( import (
"io/fs" "io/ioutil"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -14,10 +13,10 @@ var sizeSuffixes = [...]string{"B", "KiB", "MiB", "GiB", "TiB"}
// ConvertFileSize converts size in bytes down to biggest units it represents. // ConvertFileSize converts size in bytes down to biggest units it represents.
// Returns converted size, unit and, a concatenation of size and unit // Returns converted size, unit and, a concatenation of size and unit
func ConvertFileSize(size int64) (float64, string, string) { func ConvertFileSize(size int64) (float64, string, string) {
var idx int idx := 0
var fSize float64 = float64(size) fSize := float64(size)
for idx = 0; fSize >= 1024; fSize /= 1024 { for ; fSize >= 1024; fSize /= 1024 {
idx++ idx++
} }
@ -25,7 +24,8 @@ func ConvertFileSize(size int64) (float64, string, string) {
fSizeStr = strings.TrimRight(fSizeStr, "0") fSizeStr = strings.TrimRight(fSizeStr, "0")
fSizeStr = strings.TrimSuffix(fSizeStr, ".") fSizeStr = strings.TrimSuffix(fSizeStr, ".")
return fSize, sizeSuffixes[idx], strings.Join([]string{fSizeStr, sizeSuffixes[idx]}, " ") return fSize, sizeSuffixes[idx],
strings.Join([]string{fSizeStr, sizeSuffixes[idx]}, " ")
} }
func DirectorySize(path string) (dirSz int64, err error) { func DirectorySize(path string) (dirSz int64, err error) {