Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Examples of zipfile :: encode and zipfile :: decode searched.

79 views
Skip to first unread message

greg

unread,
Aug 18, 2019, 3:46:42 PM8/18/19
to
Hello
Examples of zipfile :: encode and zipfile :: decode searched.

https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/zip/encode.md

How is a Zip archive created?

greg

heinrichmartin

unread,
Aug 18, 2019, 5:12:20 PM8/18/19
to
While the manual has no clear example, you could tell the community what you have tried so far and what is the issue. Don't know how to work with snit objects? Don't know whether "owned" is a boolean or a keyword?

greg

unread,
Aug 19, 2019, 1:35:07 AM8/19/19
to
Did not understand how :: zip :: encode works. That's why I'm looking for examples.

# examplezip.tcl
# hello.txt and hello.zip are deleted for the program!
#! /usr/bin/env wish
package require Tk
package require zipfile::decode
package require zipfile::encode

catch {
package require tkcon
tkcon show
}

set srcfile hello.txt
set destfile hello.zip
set destdir "./"
set overwrite 0
catch { file delete $destfile}

close [open $srcfile a]

set zipobject [::zipfile::encode %AUTO%]
$zipobject file: $srcfile $overwrite $srcfile
$zipobject write $destfile
$zipobject destroy

set dir [glob *.*]
puts "before: $dir"
catch [file delete $srcfile]
set dir [glob *.*]
puts "after: $dir"

set zipcontent [::zipfile::decode::content $destfile]
puts $zipcontent
::zipfile::decode::unzipfile $destfile $destdir

set dir [glob *.*]
puts "decode: $dir"

heinrichmartin

unread,
Aug 19, 2019, 3:25:06 AM8/19/19
to
On Monday, August 19, 2019 at 7:35:07 AM UTC+2, greg wrote:
> # examplezip.tcl
> # hello.txt and hello.zip are deleted for the program!
> #! /usr/bin/env wish
> package require Tk

Tk is not necessary for a minimal example.

> set zipobject [::zipfile::encode %AUTO%]
> $zipobject file: $srcfile $overwrite $srcfile
> $zipobject write $destfile
> $zipobject destroy

Looks like what you are looking for (haven't tried it out). Except for $overwrite which is misleading imo. I'd use the variable name "move", i.e. move to archive; "owned" describes the internal meaning of that argument, i.e. whether the package will cleanup that (temporary) file.

greg

unread,
Aug 19, 2019, 5:57:11 AM8/19/19
to
Thank you.

(The Trf package is not available at BAWT.
(Http://www.bawt.tcl3d.org/index.html
Is needed by zipfile package.)


#! /usr/bin/env wish
# examplezip02.tcl
# hello.txt and hello.zip are deleted for the program!
package require zipfile::decode
package require zipfile::encode

catch {
package require tkcon
tkcon show
}

set srcfile hello.txt
set destfile hello.zip
set destdir "./"
set move 0
catch { file delete $destfile}

close [open $srcfile a]

set zipobject [::zipfile::encode %AUTO%]
$zipobject file: $srcfile $move $srcfile
$zipobject write $destfile
$zipobject destroy

Peter Dean

unread,
Aug 19, 2019, 7:09:51 PM8/19/19
to
Have you tried zipper from the ancient critlib? It just uses zlib.
https://equi4.com/critlib/

use like this (example using a memchan from a Google earth network link
server returning a kmz)

set fd [tcl::chan::memchan]
zipper::initialize $fd
zipper::addentry doc.kml \
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n[$doc asXML]"
foreach {name data} $icons {
zipper::addentry icons/$name [::base64::decode $data]
}
zipper::finalize
chan seek $fd 0
Httpd_ReturnData $sock application/vnd.google-earth.kmz [read $fd]
close $fd

greg

unread,
Aug 20, 2019, 8:29:05 AM8/20/19
to
Thanks for the hint.

zipper 0.2 :Zip A Directory
https://wiki.tcl-lang.org/page/Zip+A+Directory

zipper 0.12 : Using zipper to create zip files
https://wiki.tcl-lang.org/page/Using+zipper+to+create+zip+files

zipper 0.11 : zipper 0.https://equi4.com/critlib/

my Example examplezipper.tcl

#! /usr/bin/env wish
# hello.txt and hello.zip are deleted for the program!
# zipper.tcl 0.2
# https://wiki.tcl-lang.org/page/Zip+A+Directory
# under Ms Windows :in zipper.tcl : proc zcopy : catch {file attributes ${to} -permissions ${mode}}
#
source zipper.tcl

catch {
package require tkcon
tkcon show
}

set srcfile hello.txt
set destfile hello.zip
set destdir [file normalize "./"]
set move 0
catch { file delete $destfile}

close [open $srcfile a]

set f [open $srcfile r]
fconfigure $f -translation binary
zipper::initialize [open $destfile w]
zipper::addentry $srcfile [read $f]
close $f
close [zipper::finalize]

set dir [glob *.*]
puts "before: $dir"
catch [file delete $srcfile]
set dir [glob *.*]
puts "after: $dir"

set zipcontent [zipper::zstat $destfile]
puts "zipcontent: $zipcontent"
zipper::unzip $destfile $destdir
0 new messages