PureBasic 5.50 final is out !

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: PureBasic 5.50 beta 1 is out

Post by Keya »

the 5.42 docs for Base64Decoder uses #PB_Ascii|#PB_String_NoZero, but it would also be good if it mentioned somewhere that the buffer needs to be Ascii, if indeed that's still the case! btw I think from the new 5.50 on you can use Ascii() instead of PokeS(etc,#PB_Ascii) :)
[edit] oops, i meant binary data not ascii string!
Last edited by Keya on Wed Jun 22, 2016 8:15 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic 5.50 beta 1 is out

Post by infratec »

But then I miss the flag #PB_String_NoZero for the Ascii() procedure.
Or I always have to remember that I have to use MemorySize(*encoded) - 1

Also for UTF8() :wink:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 5.50 beta 1 is out

Post by Fred »

You should use MemoryStringLength() instead of MemorySize(), as ascii strings needs to be zero terminated.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic 5.50 beta 1 is out

Post by infratec »

Fred wrote:You should use MemoryStringLength() instead of MemorySize(), as ascii strings needs to be zero terminated.
Since Base64 don't want the terminating character, I always use AllocateMemory(StringByteLength(..., #PB_Ascii)) which is without terminating character and PokeS(... #PB_String_NoZero)

Then, I think, my MemorySize() is Ok.
supercdfr
User
User
Posts: 54
Joined: Tue Mar 16, 2010 9:28 pm

Re: PureBasic 5.50 beta 1 is out

Post by supercdfr »

infratec wrote:

Code: Select all

Encoded$ = "aGVsbG8gd29ybGQ="

*encodebuffer = AllocateMemory(StringByteLength(Encoded$))
If *encodebuffer
  PokeS(*encodebuffer, Encoded$, -1, #PB_Ascii|#PB_String_NoZero)
  *outbuffer = AllocateMemory(MemorySize(*encodebuffer) * 0.8)
  If *outbuffer
    Length = Base64Decoder(*encodebuffer, MemorySize(*encodebuffer), *outbuffer, MemorySize(*outbuffer))
    Debug PeekS(*outbuffer, Length, #PB_Ascii)
    FreeMemory(*outbuffer)
  EndIf
  FreeMemory(*encodebuffer)
EndIf
Bernd
Like someone say, purebasic is not anymore BASIC :cry: .
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic 5.50 beta 1 is out

Post by infratec »

supercdfr wrote:Like someone say, purebasic is not anymore BASIC :cry: .
No, some things are not easy.
But I don't know any language where the only command is:

Code: Select all

DoWhatIWant()
:mrgreen:
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: PureBasic 5.50 beta 1 is out

Post by Keya »

easy? no no, this is Programming! Poetry is two doors down :D
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 5.50 beta 1 is out

Post by Fred »

The Base64 commands will be probably be changed somewhen to work on string instead of buffer, as it doesn't makes much sens.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: PureBasic 5.50 beta 1 is out

Post by Keya »

encode only strings? but then we wouldnt be able to encode a binary buffer such as an image? email attachments for example
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: PureBasic 5.50 beta 1 is out

Post by Little John »

The purpose of Base64 is to encode any binary data, not only strings.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic 5.50 beta 1 is out

Post by infratec »

I think Fred mean what I wrote:

for Base64Decoder() it makes sense that the input is a string.
Be more exactly: an ASCII string.

The output still needs to be a memory buffer, because it can be binary data or a string
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 5.50 beta 1 is out

Post by Fred »

Yes, that's it. It would be something like that:

Code: Select all

Result = Base64Decoder(Input$, *OutputBuffer, OutputSize)
Result$ = Base64Encoder(*InputBuffer, InputSize [, Flags])
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PureBasic 5.50 beta 1 is out

Post by ts-soft »

That's good Fred and make sense!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: PureBasic 5.50 beta 1 is out

Post by Keya »

Im just wondering about a situation where for example i read a full .EML file with its base64-encoded attachments into an AllocateMemory(Lof(hFile)) buffer, and then use wilberts FindData module to quickly locate the position of each attachment in the buffer. If Base64Decoder expects a string I would need to make a str=PeekS copy from the buffer? wouldnt be good with large attachments (slower + duplicated memory), especially with base64 sizes being +33% ?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic 5.50 beta 1 is out

Post by wilbert »

Keya wrote:Im just wondering about a situation where for example i read a full .EML file with its base64-encoded attachments into an AllocateMemory(Lof(hFile)) buffer, and then use wilberts FindData module to quickly locate the position of each attachment in the buffer. If Base64Decoder expects a string I would need to make a str=PeekS copy from the buffer? wouldnt be good with large attachments (slower + duplicated memory), especially with base64 sizes being +33% ?
If you need to decode big attachments, you could build you own high speed decoder. The Base64 specification is not that complicated.
For small attachments, the impact on memory and speed probably isn't that big.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply