Version 16 of base64

Updated 2004-07-24 13:11:40

http://tcllib.sourceforge.net/doc/base64.html


Background: Base64 is a way to encode arbitrary binary data in such a way that the result contains only printable characters and are thus able to pass unchanged even through old applications which are not 8bit-ASCII clean.

Base64 is related to UUencoding in that it uses the same mechanism of distributing the bits in 3 bytes into 4 bytes. But it uses a different table to map the resulting data into printable characters.

The above means that base64 encoded data takes one-third more space than the data before the conversion. Yes.


The Cookbook includes an example [L1 ] which processes GIFs.


Base 64 encode/decode shows an example of the Tcllib module at work.


There are incompatibilities between various base64 packages and versions of Tcl. CL has pursued this most; the root problem is a change in the semantics of binary. Tcl 8.0 with the base64 in tcllib 0.8 and before was definitely bad. This thread [L2 ] details this aspect of the change from 2.1 to 2.2 of the base64.tcl source code.


Please note that there is some base64 decoding support built into Tk which is different code than what is in tcllib. There may be other bits around as well. The reason this is important is when fixing bugs, etc.


Critcl also has a Base64 implementation, see "ascenc" in [L3 ] and a critical mindset about policy


LES on July 24, 2004: would someone tell me why this experiment fails:

 set  myFile  "test.zip"
 # unpack "test.zip" -> it works; let's go ahead

 package require base64

 # ---- open and read file ----
 set  myFP  [ open  $myFile  r ]
 set  {pure file}  [ read  $myFP ]
 close  $myFP

 # ---- encode ----
 set  {encoded file}  [ ::base64::encode  ${pure file} ]

 # puts  ${encoded file}
 # output looks good

 # ---- decode ----
 set  {decoded file}  [ ::base64::decode  ${encoded file} ]

 # ---- open and write file ----
 set  myFP  [ open  "decoded - $myFile"  w ]
         fconfigure  $myFP  -translation  binary
 puts  $myFP  ${decoded file}
 close  $myFP

 # unpack "test.zip" -> ouch! it's corrupt!

 exit

Category Package, subset Tcllib