1
0
dwelling-upload/pkg/utils/filesize.go

17 lines
427 B
Go
Raw Normal View History

package utils
import "fmt"
var sizeSuffixes = [...]string{"B", "KiB", "MiB", "GiB"}
// 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) (int64, string, string) {
var idx int
for idx = 0; size >= 1024; size /= 1024 {
}
return size, sizeSuffixes[idx], fmt.Sprint(size, sizeSuffixes[idx])
}