(Tcl) Append Encoded Binary Data to StringBuilder
Demonstrates how to append encoded binary data to the contenets of a StringBuilder.
load ./chilkat.dll
set bd [new_CkBinData]
set success [CkBinData_LoadFile $bd "qa_data/jpg/starfish.jpg"]
if {$success == 0} then {
puts "Failed to load file."
delete_CkBinData $bd
exit
}
# For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
set sb [new_CkStringBuilder]
CkStringBuilder_Append $sb "{ \"jpg\": \""
# GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
CkBinData_GetEncodedSb $bd "base64" $sb
CkStringBuilder_Append $sb "\" }"
puts [CkStringBuilder_getAsString $sb]
# Output looks like this:
# { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }
delete_CkBinData $bd
delete_CkStringBuilder $sb
|