Sample code for 30+ languages & platforms
Tcl

Zip Append StringBuilder

See more Zip Examples

Append the contents of a Chilkat StringBuilder object to a .zip.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set zip [new_CkZip]

set zipPath "c:/temp/qa_output/out.zip"

CkZip_NewZip $zip $zipPath

set sb [new_CkStringBuilder]

set i 0
while {$i < 100} {
    CkStringBuilder_AppendLine $sb "This is a test" 1
    set i [expr $i + 1]
}

CkZip_AddSb $zip "this_is_a_test.txt" $sb "utf-8"

set success [CkZip_WriteZipAndClose $zip]
if {$success == 0} then {
    puts [CkZip_lastErrorText $zip]
    delete_CkZip $zip
    delete_CkStringBuilder $sb
    exit
}

puts "Success 1."

# Perhaps you want to add a file to an existing .zip
set zip2 [new_CkZip]

# Open the .zip we just wrote..
set success [CkZip_OpenZip $zip2 $zipPath]

CkStringBuilder_Clear $sb
set i 0
while {$i < 100} {
    CkStringBuilder_AppendLine $sb "This is a test 2" 1
    set i [expr $i + 1]
}

CkZip_AddSb $zip2 "this_is_a_test_2.txt" $sb "utf-8"

set zipPath2 "c:/temp/qa_output/out2.zip"
CkZip_put_FileName $zip2 $zipPath2
set success [CkZip_WriteZipAndClose $zip2]
if {$success == 0} then {
    puts [CkZip_lastErrorText $zip2]
    delete_CkZip $zip
    delete_CkStringBuilder $sb
    delete_CkZip $zip2
    exit
}

puts "Success 2."

delete_CkZip $zip
delete_CkStringBuilder $sb
delete_CkZip $zip2