diff --git a/cmd/files.go b/cmd/files.go index bd87f92..3ad3f43 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -79,6 +79,24 @@ func (p *Path) Decrement() { p.Number = p.Number - 1 } +func humanReadableSize(bytes int) string { + const unit = 1000 + + if bytes < unit { + return fmt.Sprintf("%d B", bytes) + } + + div, exp := int64(unit), 0 + + for n := bytes / unit; n >= unit; n /= unit { + div *= unit + exp++ + } + + return fmt.Sprintf("%.1f %cB", + float64(bytes)/float64(div), "KMGTPE"[exp]) +} + func preparePath(path string) string { if runtime.GOOS == "windows" { path = fmt.Sprintf("/%v", filepath.ToSlash(path)) diff --git a/cmd/version.go b/cmd/version.go index 9ad4d62..0edc62d 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.18.3" +var Version = "0.18.4" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 74356b6..4b0a782 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -218,9 +218,10 @@ func serveStaticFile(w http.ResponseWriter, r *http.Request, paths []string) err w.Write(buf) if Verbose { - fmt.Printf("%v | Served \"%v\" to %v in %v\n", + fmt.Printf("%v | Served %v (%v) to %v in %v\n", startTime.Format(LOGDATE), filePath, + humanReadableSize(len(buf)), r.RemoteAddr, time.Since(startTime).Round(time.Microsecond), )