[edit] oops, i meant binary data not ascii string!
PureBasic 5.50 final is out !
Re: PureBasic 5.50 beta 1 is out
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!
[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.
Re: PureBasic 5.50 beta 1 is out
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()
Or I always have to remember that I have to use MemorySize(*encoded) - 1
Also for UTF8()
Re: PureBasic 5.50 beta 1 is out
You should use MemoryStringLength() instead of MemorySize(), as ascii strings needs to be zero terminated.
Re: PureBasic 5.50 beta 1 is out
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)Fred wrote:You should use MemoryStringLength() instead of MemorySize(), as ascii strings needs to be zero terminated.
Then, I think, my MemorySize() is Ok.
Re: PureBasic 5.50 beta 1 is out
Like someone say, purebasic is not anymore BASICinfratec wrote:BerndCode: 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
Re: PureBasic 5.50 beta 1 is out
No, some things are not easy.supercdfr wrote:Like someone say, purebasic is not anymore BASIC.
But I don't know any language where the only command is:
Code: Select all
DoWhatIWant()Re: PureBasic 5.50 beta 1 is out
easy? no no, this is Programming! Poetry is two doors down 
Re: PureBasic 5.50 beta 1 is out
The Base64 commands will be probably be changed somewhen to work on string instead of buffer, as it doesn't makes much sens.
Re: PureBasic 5.50 beta 1 is out
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

- Posts: 4810
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PureBasic 5.50 beta 1 is out
The purpose of Base64 is to encode any binary data, not only strings.
Re: PureBasic 5.50 beta 1 is out
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
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
Re: PureBasic 5.50 beta 1 is out
Yes, that's it. It would be something like that:
Code: Select all
Result = Base64Decoder(Input$, *OutputBuffer, OutputSize)
Result$ = Base64Encoder(*InputBuffer, InputSize [, Flags])Re: PureBasic 5.50 beta 1 is out
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: PureBasic 5.50 beta 1 is out
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% ?
Re: PureBasic 5.50 beta 1 is out
If you need to decode big attachments, you could build you own high speed decoder. The Base64 specification is not that complicated.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% ?
For small attachments, the impact on memory and speed probably isn't that big.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)



