DataFlex
DataFlex
Zip Append StringBuilder
See more Zip Examples
Append the contents of a Chilkat StringBuilder object to a .zip.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoZip
String sZipPath
Variant vSb
Handle hoSb
Integer i
Handle hoZip2
String sZipPath2
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatZip)) To hoZip
If (Not(IsComObjectCreated(hoZip))) Begin
Send CreateComObject of hoZip
End
Move "c:/temp/qa_output/out.zip" To sZipPath
Get ComNewZip Of hoZip sZipPath To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
If (Not(IsComObjectCreated(hoSb))) Begin
Send CreateComObject of hoSb
End
Move 0 To i
While (i < 100)
Get ComAppendLine Of hoSb "This is a test" True To iSuccess
Move (i + 1) To i
Loop
Get pvComObject of hoSb to vSb
Get ComAddSb Of hoZip "this_is_a_test.txt" vSb "utf-8" To iSuccess
Get ComWriteZipAndClose Of hoZip To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Success 1."
// Perhaps you want to add a file to an existing .zip
Get Create (RefClass(cComChilkatZip)) To hoZip2
If (Not(IsComObjectCreated(hoZip2))) Begin
Send CreateComObject of hoZip2
End
// Open the .zip we just wrote..
Get ComOpenZip Of hoZip2 sZipPath To iSuccess
Send ComClear To hoSb
Move 0 To i
While (i < 100)
Get ComAppendLine Of hoSb "This is a test 2" True To iSuccess
Move (i + 1) To i
Loop
Get pvComObject of hoSb to vSb
Get ComAddSb Of hoZip2 "this_is_a_test_2.txt" vSb "utf-8" To iSuccess
Move "c:/temp/qa_output/out2.zip" To sZipPath2
Set ComFileName Of hoZip2 To sZipPath2
Get ComWriteZipAndClose Of hoZip2 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip2 To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Success 2."
End_Procedure