Skip to content

Commit

Permalink
Rounding of sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Nov 21, 2018
1 parent c1473ac commit e1fdb0c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 1.3.2
VERSION = 1.3.3

APP := http-file-server
PACKAGES := $(shell go list -f {{.Dir}} ./...)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Or [download a binary](https://github.com/sgreben/http-file-server/releases/late

```sh
# Linux
curl -L https://github.com/sgreben/http-file-server/releases/download/1.3.2/http-file-server_1.3.2_linux_x86_64.tar.gz | tar xz
curl -L https://github.com/sgreben/http-file-server/releases/download/1.3.3/http-file-server_1.3.3_linux_x86_64.tar.gz | tar xz

# OS X
curl -L https://github.com/sgreben/http-file-server/releases/download/1.3.2/http-file-server_1.3.2_osx_x86_64.tar.gz | tar xz
curl -L https://github.com/sgreben/http-file-server/releases/download/1.3.3/http-file-server_1.3.3_osx_x86_64.tar.gz | tar xz

# Windows
curl -LO https://github.com/sgreben/http-file-server/releases/download/1.3.2/http-file-server_1.3.2_windows_x86_64.zip
unzip versions_1.3.2_windows_x86_64.zip
curl -LO https://github.com/sgreben/http-file-server/releases/download/1.3.3/http-file-server_1.3.3_windows_x86_64.zip
unzip versions_1.3.3_windows_x86_64.zip
```

## Use it
Expand Down
Binary file modified doc/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"html/template"
"math"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -65,17 +66,20 @@ func (f fileSizeBytes) String() string {
MB = 1024 * KB
GB = 1024 * MB
)
divBy := func(x int64) int {
return int(math.Round(float64(f) / float64(x)))
}
switch {
case f < KB:
return fmt.Sprintf("%d", f)
case f < MB:
return fmt.Sprintf("%dK", f/KB)
return fmt.Sprintf("%dK", divBy(KB))
case f < GB:
return fmt.Sprintf("%dM", f/MB)
return fmt.Sprintf("%dM", divBy(MB))
case f >= GB:
fallthrough
default:
return fmt.Sprintf("%dG", f/GB)
return fmt.Sprintf("%dG", divBy(GB))
}
}

Expand Down

0 comments on commit e1fdb0c

Please sign in to comment.