Base64Str empty string return

Report any Hollywood bugs here
Post Reply
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Base64Str empty string return

Post by fingus »

Code: Select all

s$ = "AACrj6j/AAAAAAAUDgAAAAAAAf////8gIYAECQcohwAAiAIABAQAAAAAAAOAIIf/gBDn/5QQGgBr/A="
data$ = Base64Str(s$, true)
print(data$)
Gives back an empty String under Hollywood Linux 64bit, Version 9.1.
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Base64Str empty string return

Post by Flinx »

I think your Base64 string results in binary data. What did you expect?

Code: Select all

Print(ByteLen(data$))
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Base64Str empty string return

Post by fingus »

You are right.

I want to translate this Javascript-Function translate_bytes to Hollywood. Its needed for a visualisation of our Mitsubishi-AC Units.

So i need maybe a Binary Bytes to Hex-Converter.

In my other Hollywood-Projects i did not face Byte, Binary, Hex..etc conversions so i'm a bit confused about it.

I tried ChatGTP for convertig, but it only know normal LUA which differs much from the Hollywood-Accent.
Hollywood with its String-Library has much of powerful Commands inbuild.
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Base64Str empty string return

Post by Flinx »

I don't understand this Javascript program in a hurry, it's too big for that. But I can help with special conversions, I did need a lot by myself.
For example this shows your binary data as hex string without the $ sign of the HexStr() function:

Code: Select all

Local Debugstr$=""
For Local i=0 To StrLen(data$, #ENCODING_RAW)-1
	Local byte$=MidStr((HexStr(ByteAsc(data$, i))),1)
	If StrLen(byte$)<2 Then byte$="0"..byte$
	Debugstr$=Debugstr$ ..byte$.." "
Next
DebugPrint(Debugstr$)
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Base64Str empty string return

Post by plouf »

however isnt something wrong with encoding fingus original Base64 encoded? seems that misses last byte
while with other encoded tects does ok

Code: Select all

datas$ = "AACrj6j/AAAAAAAUDgAAAAAAAf////8gIYAECQcohwAAiAIABAQAAAAAAAOAIIf/gBDn/5QQGgBr/A="  ; Original after reencode you NO /A=
;datas$="cHVyZXRleHQ="  ; puretext ok
;datas$="VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy4=" ; other binary also ok


data$ = Base64Str(dataS$, True)
DebugPrint(dataS$)
dataS$ = Base64Str(data$,False)
DebugPrint(dataS$)
Christos
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Base64Str empty string return

Post by Flinx »

plouf wrote: Thu Sep 07, 2023 10:47 pm however isnt something wrong with encoding fingus original Base64 encoded? seems that misses last byte
Yes. Maybe the string should end with ==
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Base64Str empty string return

Post by fingus »

Try this string, taken from https://community.home-assistant.io/t/m ... r/411025/5
AACyiKT/AAAAAAASCgAAAAAAAf////8sv4AEEAAkigAAiAAAAgAAAAAAAAOAIIr/gBCN/5QQAQBufw==
Maybe there was a copy-paste error by me.
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Base64Str empty string return

Post by Flinx »

By the way, now I just see that this hex output I needed some time ago can be made more elegant.

Code: Select all

Local Debugstr$=""
For Local i=0 To StrLen(data$, #ENCODING_RAW)-1
	Local byte$=FormatStr("%.2X", ByteVal(MidStr(data$,i,1, #ENCODING_RAW),#BYTE))
	Debugstr$=Debugstr$ ..byte$.." "
Next
DebugPrint(Debugstr$)
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Base64Str empty string return

Post by jPV »

fingus wrote: Wed Sep 06, 2023 4:26 pm

Code: Select all

s$ = "AACrj6j/AAAAAAAUDgAAAAAAAf////8gIYAECQcohwAAiAIABAQAAAAAAAOAIIf/gBDn/5QQGgBr/A="
data$ = Base64Str(s$, true)
print(data$)
Gives back an empty String under Hollywood Linux 64bit, Version 9.1.
It works as expected, because the decoded data starts with a null byte, which terminates a string and cuts out the rest of the data when processed as a string. So if you try to print that, or do any other string manipulation, it shows up as an empty string. Whatever you plan to do with the data, handle it as binary data.

You can see all the data when you write it as a file and examine it with a hex editor. Use StringToFile(data$, "test.dat") to try it.
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Base64Str empty string return

Post by fingus »

Ok, then this isn't a bug.

Thanks all here for your help/hints.

Topic can be closed now.
Post Reply