Add --binary-prefix to output IEC binary prefixes instead of SI decimal prefixes
This commit is contained in:
parent
f5dae78483
commit
9e2b4ad9c3
|
@ -139,6 +139,7 @@ Flags:
|
||||||
--admin-prefix string string to prepend to administrative paths
|
--admin-prefix string string to prepend to administrative paths
|
||||||
-a, --all enable all supported file types
|
-a, --all enable all supported file types
|
||||||
--audio enable support for audio files
|
--audio enable support for audio files
|
||||||
|
--binary-prefix use IEC binary prefixes instead of SI decimal prefixes
|
||||||
-b, --bind string address to bind to (default "0.0.0.0")
|
-b, --bind string address to bind to (default "0.0.0.0")
|
||||||
--case-sensitive use case-sensitive matching for filters
|
--case-sensitive use case-sensitive matching for filters
|
||||||
--code enable support for source code files
|
--code enable support for source code files
|
||||||
|
|
20
cmd/files.go
20
cmd/files.go
|
@ -35,21 +35,33 @@ type scanStatsChannels struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func humanReadableSize(bytes int) string {
|
func humanReadableSize(bytes int) string {
|
||||||
const unit = 1000
|
var unit int
|
||||||
|
var suffix string
|
||||||
|
var prefixes string
|
||||||
|
|
||||||
|
if BinaryPrefix {
|
||||||
|
unit = 1024
|
||||||
|
suffix = "iB"
|
||||||
|
prefixes = "KMGTPE"
|
||||||
|
} else {
|
||||||
|
unit = 1000
|
||||||
|
suffix = "B"
|
||||||
|
prefixes = "kMGTPE"
|
||||||
|
}
|
||||||
|
|
||||||
if bytes < unit {
|
if bytes < unit {
|
||||||
return fmt.Sprintf("%d B", bytes)
|
return fmt.Sprintf("%d B", bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
div, exp := int64(unit), 0
|
div, exp := unit, 0
|
||||||
|
|
||||||
for n := bytes / unit; n >= unit; n /= unit {
|
for n := bytes / unit; n >= unit; n /= unit {
|
||||||
div *= unit
|
div *= unit
|
||||||
exp++
|
exp++
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%.1f %cB",
|
return fmt.Sprintf("%.1f %c%s",
|
||||||
float64(bytes)/float64(div), "KMGTPE"[exp])
|
float64(bytes)/float64(div), prefixes[exp], suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func kill(path string, index *fileIndex) error {
|
func kill(path string, index *fileIndex) error {
|
||||||
|
|
|
@ -14,13 +14,14 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AllowedCharacters string = `^[A-z0-9.\-_]+$`
|
AllowedCharacters string = `^[A-z0-9.\-_]+$`
|
||||||
ReleaseVersion string = "3.6.1"
|
ReleaseVersion string = "3.7.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AdminPrefix string
|
AdminPrefix string
|
||||||
All bool
|
All bool
|
||||||
Audio bool
|
Audio bool
|
||||||
|
BinaryPrefix bool
|
||||||
Bind string
|
Bind string
|
||||||
CaseSensitive bool
|
CaseSensitive bool
|
||||||
Code bool
|
Code bool
|
||||||
|
@ -111,6 +112,7 @@ func init() {
|
||||||
rootCmd.Flags().StringVar(&AdminPrefix, "admin-prefix", "", "string to prepend to administrative paths")
|
rootCmd.Flags().StringVar(&AdminPrefix, "admin-prefix", "", "string to prepend to administrative paths")
|
||||||
rootCmd.Flags().BoolVarP(&All, "all", "a", false, "enable all supported file types")
|
rootCmd.Flags().BoolVarP(&All, "all", "a", false, "enable all supported file types")
|
||||||
rootCmd.Flags().BoolVar(&Audio, "audio", false, "enable support for audio files")
|
rootCmd.Flags().BoolVar(&Audio, "audio", false, "enable support for audio files")
|
||||||
|
rootCmd.Flags().BoolVar(&BinaryPrefix, "binary-prefix", false, "use IEC binary prefixes instead of SI decimal prefixes")
|
||||||
rootCmd.Flags().StringVarP(&Bind, "bind", "b", "0.0.0.0", "address to bind to")
|
rootCmd.Flags().StringVarP(&Bind, "bind", "b", "0.0.0.0", "address to bind to")
|
||||||
rootCmd.Flags().BoolVar(&CaseSensitive, "case-sensitive", false, "use case-sensitive matching for filters")
|
rootCmd.Flags().BoolVar(&CaseSensitive, "case-sensitive", false, "use case-sensitive matching for filters")
|
||||||
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files")
|
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files")
|
||||||
|
|
Loading…
Reference in New Issue