1
0
Fork 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
1 changed files with 6 additions and 6 deletions

View File

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