In ConvertFileSize code was cosmetically changed a little.
This commit is contained in:
parent
54f87951c1
commit
d94030a4e8
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user