Add b suffix so we can specify bytes in --bwlimit, --min-size etc
Fixes #449
This commit is contained in:
+6
-1
@@ -94,7 +94,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
pflag.VarP(&bwLimit, "bwlimit", "", "Bandwidth limit in kBytes/s, or use suffix k|M|G")
|
||||
pflag.VarP(&bwLimit, "bwlimit", "", "Bandwidth limit in kBytes/s, or use suffix b|k|M|G")
|
||||
}
|
||||
|
||||
// Turn SizeSuffix into a string
|
||||
@@ -104,6 +104,9 @@ func (x SizeSuffix) String() string {
|
||||
switch {
|
||||
case x == 0:
|
||||
return "0"
|
||||
case x < 1024:
|
||||
scaled = float64(x)
|
||||
suffix = "b"
|
||||
case x < 1024*1024:
|
||||
scaled = float64(x) / 1024
|
||||
suffix = "k"
|
||||
@@ -132,6 +135,8 @@ func (x *SizeSuffix) Set(s string) error {
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.':
|
||||
suffixLen = 0
|
||||
multiplier = 1 << 10
|
||||
case 'b', 'B':
|
||||
multiplier = 1
|
||||
case 'k', 'K':
|
||||
multiplier = 1 << 10
|
||||
case 'm', 'M':
|
||||
|
||||
+3
-1
@@ -12,7 +12,7 @@ func TestSizeSuffixString(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{0, "0"},
|
||||
{102, "0.100k"},
|
||||
{102, "102b"},
|
||||
{1024, "1k"},
|
||||
{1024 * 1024, "1M"},
|
||||
{1024 * 1024 * 1024, "1G"},
|
||||
@@ -34,6 +34,8 @@ func TestSizeSuffixSet(t *testing.T) {
|
||||
err bool
|
||||
}{
|
||||
{"0", 0, false},
|
||||
{"1b", 1, false},
|
||||
{"102B", 102, false},
|
||||
{"0.1k", 102, false},
|
||||
{"0.1", 102, false},
|
||||
{"1K", 1024, false},
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
pflag.VarP(&minSize, "min-size", "", "Don't transfer any file smaller than this in k or suffix k|M|G")
|
||||
pflag.VarP(&maxSize, "max-size", "", "Don't transfer any file larger than this in k or suffix k|M|G")
|
||||
pflag.VarP(&minSize, "min-size", "", "Don't transfer any file smaller than this in k or suffix b|k|M|G")
|
||||
pflag.VarP(&maxSize, "max-size", "", "Don't transfer any file larger than this in k or suffix b|k|M|G")
|
||||
}
|
||||
|
||||
// rule is one filter rule
|
||||
|
||||
Reference in New Issue
Block a user