Working with my previous
Base64 library, I was trying to implement the added support into my TMX library. The problem, TMX data was encoded from raw bytes and not the string equivalent seen in the XML.
Use this function in conjunction with the code snippet linked above. It will create a global array called B64 which stores the decoded bytes, and the function returns the size of the array. When you're done with the data, just undim B64[]
function decode64ToByteArray(decode as string)
if isBase64(decode) = 0 then exitfunction
// Determine size of byte array
for i = len(decode) to 1 step -1
if mid(decode, i, 1) = "=" then inc e else exit
next i
size = (len(decode) / 4) * 3 - e
Global dim B64[size]
length = len(decode)
index = 0
for i = 1 to length step 4
inc index
c1$ = mid(decode, i, 1)
c2$ = "A"
c3$ = "A"
c4$ = "A"
if i+1 <= length then c2$ = mid(decode, i+1, 1)
if i+2 <= length then c3$ = mid(decode, i+2, 1)
if i+3 <= length then c4$ = mid(decode, i+3, 1)
b1 = decodeChar(c1$)
b2 = decodeChar(c2$)
b3 = decodeChar(c3$)
b4 = decodeChar(c4$)
B64[index] = b1<<2 || b2>>4
if c3$ <> "="
inc index
B64[index] = ((b2&&0xf)<<4) || (b3>>2)
endif
if c4$ <> "="
inc index
B64[index] = ((b3&&0x3)<<6) || b4
endif
next i
endfunction size
As a side note, using 64 for the base in the val() command crashes AppGameKit for me.