PureBasic
PureBasic
Unzip an AES Encrypted Text File directly into a String Variable
See more Zip Examples
A common need is to unzip from an AES encrypted Zip archive directly into a string variable, such that the unencrypted file never resides on disk, even temporarily. This example shows how to do it.Chilkat PureBasic Downloads
IncludeFile "CkZip.pb"
IncludeFile "CkZipEntry.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
zip.i = CkZip::ckCreate()
If zip.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; This example opens a WinZip-compatible AES encrypted
; .zip that contains a single file: hamlet.xml.
; It decrypts and unzips hamlet.xml directly into a string
; variable.
CkZip::ckSetPassword(zip,"secret")
success = CkZip::ckOpenZip(zip,"qa_data/hamlet.zip")
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
ProcedureReturn
EndIf
entry.i = CkZipEntry::ckCreate()
If entry.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkZip::ckEntryOf(zip,"hamlet.xml",entry)
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
CkZipEntry::ckDispose(entry)
ProcedureReturn
EndIf
; lineEndingBehavior:
; 0 = leave unchanged.
; 1 = convert all to bare LF's
; 2 = convert all to CRLF's
lineEndingBehavior.i = 0
srcCharset.s = "utf-8"
xmlText.s = CkZipEntry::ckUnzipToString(entry,lineEndingBehavior,srcCharset)
Debug xmlText
CkZip::ckDispose(zip)
CkZipEntry::ckDispose(entry)
ProcedureReturn
EndProcedure