Sample code for 30+ languages & platforms
Xbase++

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oBd
LOCAL oSb

nSuccess := 0

oBd := CreateObject("Chilkat.BinData")

nSuccess := oBd:LoadFile("qa_data/jpg/starfish.jpg")
IF (nSuccess == 0)
    ? "Failed to load file."
    oBd:destroy()
    RETURN
ENDIF

//  For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
oSb := CreateObject("Chilkat.StringBuilder")
oSb:Append('{ "jpg": "')
//  GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
oBd:GetEncodedSb("base64", oSb)
oSb:Append('" }')

? oSb:GetAsString()

//  Output looks like this:
//   { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }

oBd:destroy()
oSb:destroy()