MCPcopy
hub / github.com/lxc/incus / GetByteSizeString

Function GetByteSizeString

shared/units/units.go:160–175  ·  view source on GitHub ↗

GetByteSizeString takes a number of bytes and precision and returns a human representation of the amount of data.

(input int64, precision uint)

Source from the content-addressed store, hash-verified

158// GetByteSizeString takes a number of bytes and precision and returns a
159// human representation of the amount of data.
160func GetByteSizeString(input int64, precision uint) string {
161 if input < 1000 {
162 return fmt.Sprintf("%dB", input)
163 }
164
165 value := float64(input)
166
167 for _, unit := range []string{"kB", "MB", "GB", "TB", "PB", "EB"} {
168 value = value / 1000
169 if value < 1000 {
170 return fmt.Sprintf("%.*f%s", precision, value, unit)
171 }
172 }
173
174 return fmt.Sprintf("%.*fEB", precision, value)
175}
176
177// GetByteSizeStringIEC takes a number of bytes and precision and returns a
178// human representation of the amount of data using IEC units.

Callers 15

incusDownloadImageFunction · 0.92
CreateImageMethod · 0.92
GetImageFileMethod · 0.92
GetInstanceBackupFileMethod · 0.92
SetProgressMetadataFunction · 0.92
migrateSendLiveMethod · 0.92
progressWrapperRenderFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…