Sample code for 30+ languages & platforms
PureBasic

Unzip Text File to String

See more Zip Examples

Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to 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

    success = CkZip::ckOpenZip(zip,"qa_data/zips/EC16100.zip")
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkZip::ckDispose(zip)
        ProcedureReturn
    EndIf

    ; Get the 1st file in the .zip
    entry.i = CkZipEntry::ckCreate()
    If entry.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkZip::ckEntryAt(zip,0,entry)
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkZip::ckDispose(zip)
        CkZipEntry::ckDispose(entry)
        ProcedureReturn
    EndIf

    fileContents.s = CkZipEntry::ckUnzipToString(entry,0,"utf-8")
    Debug fileContents


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


    ProcedureReturn
EndProcedure