(PureBasic) Base64 Encode a File
PureBasic to Base64 encode the contents of a file.
IncludeFile "CkFileAccess.pb"
Procedure ChilkatExample()
; Get the contents of a file into a base64 encoded string:
fac.i = CkFileAccess::ckCreate()
If fac.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
strBase64.s = CkFileAccess::ckReadBinaryToEncoded(fac,"c:/data/something.pdf","base64")
If CkFileAccess::ckLastMethodSuccess(fac) <> 1
Debug CkFileAccess::ckLastErrorText(fac)
CkFileAccess::ckDispose(fac)
ProcedureReturn
EndIf
; Now write the string to a file:
success.i = CkFileAccess::ckWriteEntireTextFile(fac,"c:/data/something_pdf_base64.txt",strBase64,"us-ascii",0)
If success <> 1
Debug CkFileAccess::ckLastErrorText(fac)
CkFileAccess::ckDispose(fac)
ProcedureReturn
EndIf
Debug "Success!"
CkFileAccess::ckDispose(fac)
ProcedureReturn
EndProcedure
|