1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-31 02:29:18 +02:00

WIP tier CLI

This commit is contained in:
binwiederhier 2023-02-06 22:38:22 -05:00
parent 9b54f63eb1
commit e3b39f670f
10 changed files with 367 additions and 35 deletions

View file

@ -222,6 +222,20 @@ func ParseSize(s string) (int64, error) {
}
}
// FormatSize formats bytes into a human-readable notation, e.g. 2.1 MB
func FormatSize(b int64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d bytes", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
// ReadPassword will read a password from STDIN. If the terminal supports it, it will not print the
// input characters to the screen. If not, it'll just read using normal readline semantics (useful for testing).
func ReadPassword(in io.Reader) ([]byte, error) {