Swift
Swift
Append Encoded Binary Data to StringBuilder
Demonstrates how to append encoded binary data to the contenets of a StringBuilder.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let bd = CkoBinData()!
success = bd.loadFile(path: "qa_data/jpg/starfish.jpg")
if success == false {
print("Failed to load file.")
return
}
// For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
let sb = CkoStringBuilder()!
sb.append(value: "{ \"jpg\": \"")
// GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
bd.getEncodedSb(encoding: "base64", sb: sb)
sb.append(value: "\" }")
print("\(sb.getAsString()!)")
// Output looks like this:
// { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }
}