Swift
Swift
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// Get the contents of a file into a base64 encoded string:
let fac = CkoFileAccess()!
var strBase64: String? = fac.readBinary(toEncoded: "c:/data/something.pdf", encoding: "base64")
if fac.lastMethodSuccess != true {
print("\(fac.lastErrorText!)")
return
}
// Now write the string to a file:
success = fac.writeEntireTextFile(path: "c:/data/something_pdf_base64.txt", fileData: strBase64, charset: "us-ascii", includePreamble: false)
if success != true {
print("\(fac.lastErrorText!)")
return
}
print("Success!")
}