Function test()
request = CreateObject("roUrlTransfer")
request.SetCertificatesFile("common:/certs/ca-bundle.crt")
request.AddHeader("X-Roku-Reserved-Dev-Id", "")
request.InitClientCertificates()
request.SetUrl("https://gist.githubusercontent.com/quartern/c4bb656c005ded4b3c3bead99dd5b71a/raw/e35ae64009457d050e24cbdf0ebf22fc8d4aecd8/gistfile1.txt")
tmpfile="tmp:/quartern_resp.txt"
request.GetToFile(tmpfile)
ba = CreateObject("roByteArray")
if not ba.ReadFile(tmpfile)
print "ReadFile failed"
else if ba.count() < 1
print "Empty response"
else
' we know we get these with quotes - strip them
txt=ba.ToAsciiString()
print "B4 STRIP >>>"+txt.left(10)+"..."+txt.right(10)+"<<<"
ba.pop()
ba.shift()
txt=ba.ToAsciiString()
print "AFTER STRIP >>>"+txt.left(10)+"..."+txt.right(10)+"<<<, count=",ba.count()
' decode and parse
ba.FromBase64String(ba.ToAsciiString())
txt=ba.ToAsciiString()
print "AFTER DECODE >>>"+txt.left(10)+"..."+txt.right(10)+"<<<, count=",ba.count()
theData=ParseJSON(ba.ToAsciiString())
endif
DeleteFile(tmpfile)
theData.x=1 ' just force debugger on fail
return theData
end Function
B4 STRIP >>>"eyJ3Y2ZJc...lNiI6W119"<<<
AFTER STRIP >>>eyJ3Y2ZJcC...xlNiI6W119<<<, count= 271071
AFTER DECODE >>>{"wcfIp":[...??? ??? ??<<<, count= 203301
BRIGHTSCRIPT: ERROR: ParseJSON: Unterminated string: ...
,"Table6":[]}
15k\/INek16jXpyAxIiwibWVkaWFfY29kZSI6Ijg4OTIzNyIsIm1lZGlhX2Rlc2MiOiLXkNeZ16TXlCD
' based on https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
Function Decode64FromFile(fname as String) as String
WHITESPACE_CHR=64
EQUALS_CHR=65
INVALID_CHR=66
d = [
66,66,66,66,66,66,66,66,66,66,64,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,62,66,66,66,63,52,53,
54,55,56,57,58,59,60,61,66,66,66,65,66,66,66, 0, 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,66,66,66,66,66,66,26,27,28,
29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
66,66,66,66,66,66
]
iter = 0
buf = 0
currLen = 0
baIn = CreateObject("roByteArray")
baOut = CreateObject("roByteArray")
baIn.ReadFile(fname)
inCount=0
for each inByte in baIn
c = d[inByte]
inCount+=1
if c=INVALID_CHR
print "Invalid character X at postion Y", inByte, inCount-1
else if c=WHITESPACE_CHR
' ignore
print "ignore whitespace"
else if c=EQUALS_CHR
exit for
else
buf = (buf<<6) or c
iter+=1 ' increment the number of iteration
' If the buffer is full, split it into bytes
if iter = 4
currLen += 3
baOut.push((buf >> 16) and 255)
baOut.push((buf >> 😎 and 255)
baOut.push(buf and 255)
buf = 0
iter = 0
end if
end if
end for
if iter = 3
currLen += 2
baOut.push((buf >> 10) and 255)
baOut.push((buf >> 2) and 255)
else if iter = 2
currLen += 1
baOut.push((buf >> 4) and 255)
end if
return baOut.ToAsciiString()
end function
"Arthy74" wrote:
amazing, works better than the builtin FromBase64String
Thank you so much !
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. You will not be able to log in or post new comments or kudos during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 12 and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
Thanks for your patience — we’re excited to share what’s next!