GNU Zip (or ''gzip'' for short) is a stream compression program (like the UNIX [compress] program), and not an archiver (like the DOS [pkzip] program) that uses an ''unpatented'' (and unpatentable) algorithm for its compression. The program [bzip2] can compress even more, but takes more memory to do so. The [zlib] library uses the same algorithms, and can be used to process or produce gzipped files (IIRC, though there might be a header too.) This governed by three [RFC]'s * RFC 1950 [http://www.gzip.org/zlib/rfc-zlib.html] - Zlib Compressed Data Format * RFC 1951 [http://www.gzip.org/zlib/rfc-deflate.html] - Deflate Compressed Data format * RFC 1952 [http://www.gzip.org/zlib/rfc-gzip.html] - Gzip File Format See also http://en.wikipedia.org/wiki/Gzip See [GASP], [tkArchive], [TkZip], Also take a look at [bzip2] and [LZMA] for better compression rates Are there any Tcl bindings for [zlib]? '''18Aug04 [PS]''' Yes there is! tclkit has it by default and I created an extension from that. See the [zlib] page. ---- '''gunzip a file with [zlib] and Tcl''' proc gunzip { file {outfile ""} } { package require zlib # Gunzip the file # See http://www.gzip.org/zlib/rfc-gzip.html for gzip file description set in [open $file r] fconfigure $in -translation binary -buffering none set id [read $in 2] if { ![string equal $id \x1f\x8b] } { error "$file is not a gzip file." } set cm [read $in 1] if { ![string equal $cm \x8] } { error "$file: unknown compression method" } binary scan [read $in 1] b5 FLAGS puts $FLAGS foreach {FTEXT FHCRC FEXTRA FNAME FCOMMENT} [split $FLAGS ""] {} binary scan [read $in 4] i MTIME set XFL [read $in 1] set OS [read $in 1] if { $FEXTRA } { binary scan [read $in 2] S XLEN set ExtraData [read $in $XLEN] } set name "" if { $FNAME } { ead $in $XLEN] set c [read $in 1] while { $c != "\x0" } { append name $c set c [read $in 1] } } set comment "" if { $FCOMMENT } { set c [read $in 1] while { $c != "\x0" } { append comment $c set c [read $in 1] } } set CRC16 "" if { $FHCRC } { set CRC16 [read $in 2] } set cdata [read $in] close $in binary scan [string range $cdata end-7 end] ii CRC32 ISIZE set data [zlib inflate [string range $cdata 0 end-8]] if { $CRC32 != [zlib crc32 $data] } { error "gunzip Checksum mismatch." } if { $outfile == "" } { set outfile $file if { [string equal -nocase [file extension $file] ".gz"] } { set outfile [file rootname $file] } } if { [string equal $outfile $file] } { error "Will not overwrite input file. sorry." } set out [open $outfile w] fconfigure $out -translation binary -buffering none puts -nonewline $out $data close $out file mtime $outfile $MTIME } '''18Aug04 [PS]''' ---- [LES]: Would someone tell me HOW this is better than '''[[exec gzip filename]]'''? [PS]: gzip might not be installed? And with a small tweak, you'd just get the file content - put that together with vfs::tar and you might be able to mount tar.gz files... [SRIV] Stock Windows installs don't have gzip. Think cross platform. "Better" is in the eye of the beholder. Nice work. ---- [DKF]: Here's a cheap way to invoke ''gzip'' on Windows. Note that just using '''exec gzip -c <<$d''' does not work because of translation issues. proc gzip d { set data [open foo.tmp w] fconfigure $data -translation binary puts -nonewline $data $d close $data set f [open "|gzip -c