Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
let bd = CkoBinData()!
// This example will load a PDF and return it as a base64 string.
success = bd.loadFile(path: "qa_data/pdf/helloWorld.pdf")
if success != true {
print("Failed to load file.")
return
}
var b64Str: String? = bd.getEncoded(encoding: "base64")
print("\(b64Str!)")
// Now write the base64 string back to the binary PDF file:
let bd2 = CkoBinData()!
success = bd2.appendEncoded(encData: b64Str, encoding: "base64")
success = bd2.writeFile(path: "qa_output/helloWorld.pdf")
}