BrightSign BrightScript 2 Reference Guide User Manual
Page 47

47
hex or ascii base 64. Note that if you are converting a byte array to a string, and the byte
array contains a zero, the string conversion will end at that point. roByteArray will
autosize to become larger as needed. If you wish to turn off this behavior, then use the
SetResize() function. If you read an uninitialized index, "invalid" is returned.
roByteArray supports the ifArray interface, and so can be accessed with the array []
operator. The byte array is always accessed as unsigned bytes when using this interface.
roByteArray also supports the ifEnum interface, and so can be used with a "for each"
statement. In addition, the ifByteArray interface provides various functions listed below.
ifByteArray Interface Functions:
WriteFile(path) As Boolean
WriteFile(path , start_index, length) As Boolean
ReadFile(path) As Boolean
ReadFile(path, start_index, length ) As Boolean
AppendFile(path) As Boolean
SetResize(minimum_allocation_size, autoresize) As Boolean
ToHexString() As String
FromHexString(hexstring) As Void
ToBase64String() As String
FromBase64String(base65string) As Void
ToAsciiString() As String
FromAsciiString(string)
GetSignedByte(index) As Integer
IsLittleEndianCPU() As Boolean
Here are a few examples of roByteArray:
ba=CreateObject("roByteArray")
ba.FromAsciiString("leasure.")
if ba.ToBase64String()<>"bGVhc3VyZS4=" then stop
ba=CreateObject("roByteArray")
ba.fromhexstring("00FF1001")
if ba[0]<>0 or ba[1]<>255 or ba[2]<>16 or ba[3]<>1 then
stop
ba=CreateObject("roByteArray")
for x=0 to 4000
ba.push(x) ' will truncate when x bigger than 255
next
ba.WriteFile("ByteArrayTestFile")
ba2=CreateObject("roByteArray")