(PureBasic) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.
IncludeFile "CkZip.pb"
IncludeFile "CkZipEntry.pb"
Procedure ChilkatExample()
; 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.i = CkZip::ckOpenZip(zip,"qa_data/zips/EC16100.zip")
If success <> 1
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
ProcedureReturn
EndIf
; Get the 1st file in the .zip
entry.i = CkZip::ckGetEntryByIndex(zip,0)
If CkZip::ckLastMethodSuccess(zip) <> 1
Debug "No files in this zip."
CkZip::ckDispose(zip)
ProcedureReturn
EndIf
fileContents.s = CkZipEntry::ckUnzipToString(entry,0,"utf-8")
Debug fileContents
CkZipEntry::ckDispose(entry)
CkZip::ckDispose(zip)
ProcedureReturn
EndProcedure
|