I'm calling unzip from a unix shell.
catch {exec /bin/sh -c "unzip $zipfile" }
but that would need changing for Windoze and I'm not sure how common it
is to have a command line version of unzip on a windows platform. I
suspect not very. Hence if I could use a library to decompress the file,
it would be useful.
--
Dave (from the UK)
Please note my email address changes periodically to avoid spam.
It is always of the form: month...@southminster-branch-line.org.uk
Hitting reply will work for a few months only - later set it manually.
http://witm.sourceforge.net/ (Web based Mathematica front end)
>Is there any way inside Tcl to open a zipped file (one file in one
>zipefile) and convert uncompress it?
Have you looked at the virtual file system obtained with
package require vfs
? It allows you to mount the zip file anywhere in
your filesystem, as if it were a directory. Read-only,
but cool nonetheless.
You could then use [file copy] to extract a file from the
zip archive.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
It sounds complex, but I'll take a closer look later.
I haven't tried it myself, it just got posted to the Tcl Wiki today,
but you might want to check out
--Mark
Here is a quick try at the functionality - I have only quickly tested
it but it shows the basic idea - this will take all files in the
"top" level of the zip file and return their contents.
It
package require vfs
proc read_zip name {
set data {}
set mount_point "/zip_$name"
vfs::zip::Mount $name $mount_point
foreach filename [ glob $mount_point/* ] {
if { [ file isfile $filename ] } {
set f [ open $filename ]
append data [ read $f ]
close $f
}
}
vfs::filesystem unmount $mount_point
return $data
}
set contents [ read_zip test.zip ]
Caveat here: I have not used vfs before, I just though I would see
how easy it was to solve this problem.
Regards
Palu
The Tcl [zlib] command provides an interface to the Zlib library for
compression and decompression of .gz and .zip files.
For stock Tcl, you could try using the reference implementation provided
for "TIP #234: Add Support For Zlib Compression". See
http://www.tcl.tk/cgi-bin/tct/tip/234.html for details.
More conveniently, Tclkit has the [zlib] command built-in. You can
download Tclkit from http://equi4.com/tclkit.html or use the equivalent
provided in ActiveTcl.
See http://wiki.tcl.tk/zlib for discussion.
Best wishes,
Alastair
Just so people know, that's not going in 8.5 because we want it to
integrate nicely with the channel stacking mechanism (that's also not
going in 8.5, mostly due to lack of time). Going with the zlib package
is the best bet for now.
Donal.
start $zipfile
I *think* you don't just want to launch the unzip though; you
actually want to use the contents. For that, you are indeed
best off coding and packaging everything in Tcl, as advised
elsewhere in this thread.
Considering it's built into the shell in XP, yah. I've honestly never
seen a Windows system that this wouldn't work on. (And I think I'm the
only person I know who actually paid for WinZip, too, but that's another
rant. :-)
--
Darren New / San Diego, CA, USA (PST)
Scruffitarianism - Where T-shirt, jeans,
and a three-day beard are "Sunday Best."
> Is there any way inside Tcl to open a zipped file (one file in one
> zipefile) and convert uncompress it?
>
> I'm calling unzip from a unix shell.
>
>
> catch {exec /bin/sh -c "unzip $zipfile" }
>
>
> but that would need changing for Windoze and I'm not sure how common it
> is to have a command line version of unzip on a windows platform. I
> suspect not very. Hence if I could use a library to decompress the file,
> it would be useful.
>
>
You may want to take a look at freeWrap at http://freewrap.sourceforge.net/
FreeWrap can be used as a single-file version of TCL/TK and has the ability
to mount ZIP files onto a directory path of your choosing.
For example, suppose you have a ZIP archive named example1.zip and suppose
this archive contains three files named abc.tcl, pqrs.gif, and xyz.tcl. You
can mount this ZIP archive as follows:
zvfs::mount example1.zip /zip1
After executing the above command, the contents of the ZIP archive appear to
be files in the /zip1 directory. So, for instance, you can now execute
commands like these:
source /zip1/abc.tcl
image create photo img1 -data /zip1/pqrs.gif
puts "The size of file xyz.tcl is [file size /zip1/xyz.tcl]"
The files /zip1/abc.tcl, /zip1/pqrs.gif, and /zip1.xyz.tcl never really
exist as separate files on your disk drive. They are always contained
within the ZIP archive and are not unpacked. The ZVFS extension built into
freeWrap intercepts Tcl's attempt to open and read these files and
substitutes data from the ZIP archive that is extracted and decompressed on
the fly.
Dennis LaBelle
> I'm calling unzip from a unix shell.
> catch {exec /bin/sh -c "unzip $zipfile" }
Use
exec unzip $zipfile
and it would work on any platform provided that command-line unzip is
available in the PATH
> but that would need changing for Windoze and I'm not sure how common it
> is to have a command line version of unzip on a windows platform. I
You can distribute unzip program from InfoZip with your application.
License is quite liberal, much like license of tcl itself.
> suspect not very. Hence if I could use a library to decompress the file,
> it would be useful.
There is zipfs virtual file system in TclVfs package. It requires
Trf extension which contain interface to zlib decompression library
(decompression is a bit too computation intensive to be done in pure
Tcl), but handles format of Zip archive (i.e. directory listings,
finding compressed data for particular file) in pure Tcl.