1
0

convertFileSize() now returns only a concatination of a converted size and a size unit.

This commit is contained in:
Alexander Andreev 2022-12-17 22:45:30 +04:00
parent a567a27c69
commit 0798ba6602
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -8,8 +8,8 @@ import (
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) {
// Returns a concatenation of a converted size and a unit
func convertFileSize(size int64) string {
var idx int
var fSize float64 = float64(size)
for idx = 0; fSize >= 1024; fSize /= 1024 {
@ -18,5 +18,5 @@ func convertFileSize(size int64) (float64, string, string) {
fSizeStr := strconv.FormatFloat(fSize, 'f', 3, 64)
fSizeStr = strings.TrimRight(fSizeStr, "0")
fSizeStr = strings.TrimSuffix(fSizeStr, ".")
return fSize, sizeSuffixes[idx], fSizeStr + " " + sizeSuffixes[idx]
return fSizeStr + " " + sizeSuffixes[idx]
}