summaryrefslogtreecommitdiff
path: root/bytes.go
blob: 7b40804e58eda18c525799d83d9b948257a0a1cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cobol

import (
	"fmt"
)

// returns a human readable string of the bytes
func Bytes(anInt any) string {
	return "todo"
}

// returns a human readable string of the bytes
// also returns the error if there was one
func BytesCheck(anInt any) (string, error) {
	return "todo", NoBytes
}

// returns an int. will try to convert strings
func GetBytes(anInt any) (int, error) {
	return 0, NoBytes
}

// This isn't for the marketing department
// so this isn't going to use 'MiB' and 'GiB'
func HumanFormatBytes(b int) string {
	if b < 2000 {
		return fmt.Sprintf("%d B", b)
	}

	kb := int(b / 1024)
	if kb < 2000 {
		return fmt.Sprintf("%d KB", kb)
	}

	mb := int(b / (1024 * 1024))
	if mb < 2000 {
		return fmt.Sprintf("%d MB", mb)
	}

	gb := int(b / (1024 * 1024 * 1024))
	if gb < 2000 {
		return fmt.Sprintf("%d GB", gb)
	}

	tb := int(b / (1024 * 1024 * 1024 * 1024))
	return fmt.Sprintf("%d TB", tb)
}