Application Framework Reference

App Server Utilities API

convert_to_bytes()

The convert_to_bytes() function converts byte string value notation, containing a size specification, to an integer or float value, using base-2 computation.

Synopsis

numericValue = convert_to_bytes(byteValue)

Parameters

byteValue

String

Byte string value with one of the following unit specifications:

YB
ZB
EB
PB
TB
GB
MB
KB
YiB
ZiB
EiB
PiB
TiB
GiB
MiB
KiB
B

Format specification examples:

10MB
1.4 GB
1000 YiB
1000YB

Note: The value may not contain a thousands separator comma, and uses a period (.) to denote decimal.

Examples:

convert_to_bytes('10MB') returns 102400000 convert_to_bytes('40 GB') returns 42949672960 convert_to_bytes('300') returns 300

Return Value

Integer/Float

Integer or float representation of byteValue .

Exceptions

ValueError

'unrecognized units: %s' % units

ValueError

'cannot convert to bytes: %s' % byteValue

Example

from splunk.appserver.mrsparkle.lib import util    

byteVal = '10000PB'
try:
    bytes = util.convert_to_bytes(byteVal)
except:
    pass