[GSoC 2021] base64 encoding in "strings" package

Hello maintainers,

While searching for a method to base64 encode files (png images). I found the “strings” package which has a function base64encode that does what I need. The problem is when I use the last release I got the following errors:

pcregexp.cc: In function ‘octave_value_list Fpcregexp(const octave_value_list&, int)’:
pcregexp.cc:52:9: error: ‘gripe_wrong_type_arg’ was not declared in this scope
         gripe_wrong_type_arg("pcregexp", args(0));
         ^~~~~~~~~~~~~~~~~~~~
pcregexp.cc:52:9: note: suggested alternative: ‘err_wrong_type_arg’
         gripe_wrong_type_arg("pcregexp", args(0));
         ^~~~~~~~~~~~~~~~~~~~
         err_wrong_type_arg

The most recent version that worked with me is 1.0.6. But, I got some warnings. Is this package still maintained Or should I go in another direction (writing base64 decoder/encoder should be easy)
@siko1056, What do you think?

Octave core contains base64_encode and base64_decode. Would those functions work for you?

Edit: If you are targeting Octave 7, there’ll also be matlab.net.base64encode and matlab.net.base64decode.

1 Like

It doesn’t produce the correct encoding in the case of PNG images. Maybe this is because it is made for the transmission and reception of data.

Do you have a small example, what you are trying to encode / decode?

base64_encode and base64_decode might be somewhat un-intuitive in that they are targeted at double precision content.
I’m guessing your data is of integer type?
In that case, try typecasting to and from double. You might need to append or remove trailing zeros to account for the fact that double precision numbers have 8 bytes.

matlab.net.base64encode and matlab.net.base64decode might be easier to use because they work on bytes. But like I wrote before, these functions aren’t available before Octave 7.

I am trying to encode PNG images in order to embed them in the notebook.

Unfortunately, there are no small examples of this.

But to check, I used an online encoder. I opened the image file using fopen and fread. and when using base64encode gave me the same result I got from the online encoder. The results with base64_encode were different.

Since I read it from a file using fread it comes as a float. I typecast it into uint8 and it produced the correct output!
Thanks for the help.