Sample code for 30+ languages & platforms
PureBasic Requires Chilkat v11.0.0+

Unzip Encrypted Text into a String Variable

See more Zip Examples

Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.

Chilkat PureBasic Downloads

PureBasic
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

    ;  Set the password required for decrypting.
    CkZip::setCkDecryptPassword(zip, "myPassword")

    success = CkZip::ckOpenZip(zip,"encrypted.zip")
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkZip::ckDispose(zip)
        ProcedureReturn
    EndIf

    ;  Locate the file within the Zip to be unzipped into a string variable:
    entry.i = CkZipEntry::ckCreate()
    If entry.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkZip::ckEntryMatching(zip,"*.csv",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"

    strCsv.s = CkZipEntry::ckUnzipToString(entry,lineEndingBehavior,srcCharset)
    Debug strCsv


    CkZip::ckDispose(zip)
    CkZipEntry::ckDispose(entry)


    ProcedureReturn
EndProcedure