mirror of
https://github.com/nxshock/simplefileshare.git
synced 2025-07-02 00:13:36 +05:00
Import project
This commit is contained in:
parent
f0e39831c2
commit
1b0cbbf5cd
13 changed files with 588 additions and 0 deletions
28
utils.go
Normal file
28
utils.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func sizeToApproxHuman(s int64) string {
|
||||
t := []struct {
|
||||
Name string
|
||||
Val int64
|
||||
}{
|
||||
{"EiB", 1 << 60},
|
||||
{"PiB", 1 << 50},
|
||||
{"TiB", 1 << 40},
|
||||
{"GiB", 1 << 30},
|
||||
{"MiB", 1 << 20},
|
||||
{"KiB", 1 << 10}}
|
||||
|
||||
var v float64
|
||||
for i := 0; i < len(t); i++ {
|
||||
v = float64(s) / float64(t[i].Val)
|
||||
if v < 1.0 {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f %s", v, t[i].Name)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f KiB", v)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue