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
|
[
define_tag:'lp_display_filesize',
-description='Returns the filesize formatted for display given the number of bytes.',
-priority='replace',
-required='filesize',
-optional='kb', // returns everything in kilobytes
-encodenone;
// based on a tag from Jason Huck
// http://tagswap.net/bytes_format
// and Pier Kuipers
// http://tagswap.net/PK_ByteSize
local:
'bytes' = decimal: #filesize,
'blocksize' = 1024.0,
'exp' = 1,
'units' = (:'B ','KB','MB','GB','TB');
if: (local_defined:'kb');
if: (lp_decimal_float: #bytes / #blocksize) == 0;
local:'return' = (lp_decimal_fixed: #bytes / #blocksize);
else;
local:'return' = ((lp_decimal_fixed: #bytes / #blocksize) + 1);
/if;
#return->(setformat: -groupchar=',');
return: #return ' KB';
/if;
#bytes->(setformat: -precision=2);
while: true;
if: #bytes < #blocksize;
return: (#exp <= 2 ? (integer:#bytes) | #bytes) ' ' #units->(get:#exp);
else; // >=
#bytes /= #blocksize;
#exp += 1;
/if;
/while;
/define_tag;
]
|