1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

fs: Extend SizeSuffix to include TB and PB for rclone about

This commit is contained in:
Nick Craig-Wood
2018-04-17 21:47:20 +01:00
parent 1ac6dacf0f
commit ef3bcec76c
3 changed files with 30 additions and 15 deletions

View File

@@ -22,18 +22,24 @@ func (x SizeSuffix) string() (string, string) {
return "off", ""
case x == 0:
return "0", ""
case x < 1024:
case x < 1<<10:
scaled = float64(x)
suffix = ""
case x < 1024*1024:
scaled = float64(x) / 1024
case x < 1<<20:
scaled = float64(x) / (1 << 10)
suffix = "k"
case x < 1024*1024*1024:
scaled = float64(x) / 1024 / 1024
case x < 1<<30:
scaled = float64(x) / (1 << 20)
suffix = "M"
default:
scaled = float64(x) / 1024 / 1024 / 1024
case x < 1<<40:
scaled = float64(x) / (1 << 30)
suffix = "G"
case x < 1<<50:
scaled = float64(x) / (1 << 40)
suffix = "T"
default:
scaled = float64(x) / (1 << 50)
suffix = "P"
}
if math.Floor(scaled) == scaled {
return fmt.Sprintf("%.0f", scaled), suffix
@@ -80,6 +86,10 @@ func (x *SizeSuffix) Set(s string) error {
multiplier = 1 << 20
case 'g', 'G':
multiplier = 1 << 30
case 't', 'T':
multiplier = 1 << 40
case 'p', 'P':
multiplier = 1 << 50
default:
return errors.Errorf("bad suffix %q", suffix)
}