-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage-unit-converter
39 lines (38 loc) · 1.12 KB
/
storage-unit-converter
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
# storage unit converter
# It must be configured at startup so that it is always available.
:global human do={
:if ([:typeof $1]="nothing") do={
:error "must provide a byte value to humanize";
};
:local input [:tonum $1];
:if ([:typeof $input]!="num") do={
:error "cannot convert $1 to number";
};
:local q;
:local r;
:local output;
:if ($input<1024) do={
:set $output "$input bytes";
} else={
:if ($input<1048576) do={
:set q ($input/1024);
:set r ($input-$q*1024);
:set r ($r/102);
:set output "$q.$r KiB";
} else={
:if ($input<1073741824) do={
:set q ($input/1048576);
:set r ($input-$q*1048576);
:set r ($r/104858);
:set output "$q.$r MiB"
} else={
:set q ($input/1073741824);
:set r ($input-$q*1073741824);
:set r ($r/107374182);
:set output "$q.$r GiB"
}
}
}
:return $output
};
:log info "start storage unit converter!";