Base64 weirdness

Mark Schonewille m.schonewille at economy-x-talk.com
Sat Oct 29 08:02:01 EDT 2011


Hi Maarten,

The difference in the number of bytes of your base 64 encoded strings equals the number of lines of these strings. Apparently, LC uses crlf where other languages use either cr or lf. I assume you are on Windows. Try reading the file as file instead of binfile and the problem should be solved (or replace crlf with lf after reading as binfile).

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/16r Start selling Color Converter today. 20% commission!

On 29 okt 2011, at 13:35, Maarten Koopmans wrote:

> Sorry for the cross-post from the forum, but this (silly) thing is
> becoming a blocker.
> 
> A (to me) subtle question, which has to do with the base64 encoding. A
> base 64 encoded binary needs to be a multiple of 4. It' what all other
> implementation seem to do as well (tested Scala (JVM) and REBOL (C
> underneath)).
> 
> But if I test with a standalone file like this:
> 
> put "/Users/maartenkoopmans/Desktop/pw.jpg" into tFilename
> put base64encode(url("binfile:" & tFilename)) into tImage
> answer "file read and converted"
> answer the length of tImage
> 
> I consistently get 7758 as length in Livecode, and 7652 in other
> implementaions (REBOL, Scala). The LC form has two bytes to much to be
> multiple of 4, and way more than the others, which are multiples of
> fours. So how do you get your data back then to display the image in a
> different environment (say, as webserver....)?
> 
> Any thoughts appreciated...
> 
> --Maarten





More information about the Use-livecode mailing list