(PureBasic) Append String as a File to a Zip
Demonstrates how to append text data as a file within a zip archive.
IncludeFile "CkZip.pb"
IncludeFile "CkZipEntry.pb"
Procedure ChilkatExample()
; This example assumes 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
zipPath.s = "c:/temp/test.zip"
; Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
CkZip::ckNewZip(zip,zipPath)
; Append a file that will contain the string "Hello World";
fileContent.s = "Hello World"
pathInZip.s = "txtFiles/helloWorld.txt"
entry.i = CkZip::ckAppendString(zip,pathInZip,fileContent)
CkZipEntry::ckDispose(entry)
CkZip::setCkFileName(zip, zipPath)
success = CkZip::ckWriteZipAndClose(zip)
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
ProcedureReturn
EndIf
Debug "Success."
CkZip::ckDispose(zip)
ProcedureReturn
EndProcedure
|