Skip to content

Commit e1fdb0c

Browse files
committed
Rounding of sizes
1 parent c1473ac commit e1fdb0c

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 1.3.2
1+
VERSION = 1.3.3
22

33
APP := http-file-server
44
PACKAGES := $(shell go list -f {{.Dir}} ./...)

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ Or [download a binary](https://github.com/sgreben/http-file-server/releases/late
6060

6161
```sh
6262
# Linux
63-
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
63+
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
6464

6565
# OS X
66-
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
66+
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
6767

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

7373
## Use it

doc/screenshot.png

1.27 KB
Loading

server.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"html/template"
6+
"math"
67
"net/http"
78
"net/url"
89
"os"
@@ -65,17 +66,20 @@ func (f fileSizeBytes) String() string {
6566
MB = 1024 * KB
6667
GB = 1024 * MB
6768
)
69+
divBy := func(x int64) int {
70+
return int(math.Round(float64(f) / float64(x)))
71+
}
6872
switch {
6973
case f < KB:
7074
return fmt.Sprintf("%d", f)
7175
case f < MB:
72-
return fmt.Sprintf("%dK", f/KB)
76+
return fmt.Sprintf("%dK", divBy(KB))
7377
case f < GB:
74-
return fmt.Sprintf("%dM", f/MB)
78+
return fmt.Sprintf("%dM", divBy(MB))
7579
case f >= GB:
7680
fallthrough
7781
default:
78-
return fmt.Sprintf("%dG", f/GB)
82+
return fmt.Sprintf("%dG", divBy(GB))
7983
}
8084
}
8185

0 commit comments

Comments
 (0)