Sample code for 30+ languages & platforms
Tcl

Convert any File to Base64 (and back)

Demonstrates how to get the contents of any file as a base64 string, and then write it back.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set bd [new_CkBinData]

# This example will load a PDF and return it as a base64 string.
set success [CkBinData_LoadFile $bd "qa_data/pdf/helloWorld.pdf"]
if {$success != 1} then {
    puts "Failed to load file."
    delete_CkBinData $bd
    exit
}

set b64Str [CkBinData_getEncoded $bd "base64"]
puts "$b64Str"

# Now write the base64 string back to the binary PDF file:
set bd2 [new_CkBinData]

set success [CkBinData_AppendEncoded $bd2 $b64Str "base64"]
set success [CkBinData_WriteFile $bd2 "qa_output/helloWorld.pdf"]

delete_CkBinData $bd
delete_CkBinData $bd2