Scroll to navigation

ns_zlib(3aolserver) AOLserver Zlib Extension ns_zlib(3aolserver)


ns_zlib - Zlib compression support


ns_zlib compress string
ns_zlib gunzip file
ns_zlib gzip string
ns_zlib gzipfile file
ns_zlib uncompress string


The ns_zlib command enables compressing and uncompressing of strings or files. The command is available if the module is loaded into AOLserver or the, nszlib.dll, or libnszlib.dylib dynamic library is loaded using the load command in a suitable tclsh such as nstclsh.

This command compresses the given string and returns a Tcl byte array object with the compressed data.

This command uncompresses the contents of the given gzipped file and returns a string as the result.

This command is similar to the gzip shell routines, compressing the given file into a new file with the .gz extension. If successful, the original uncompressed file is deleted.

This command takes a byte array object which includes compressed data and returns an uncompressed string object.


The following examples demonstrate compressing and uncompressing a string;

# Compress Tcl string set test "This is test string" set data [ns_zlib compress $test] set test [ns_zlib uncompress $data] --> returns "This is test string" # Compress the string into gzip format set gzip [ns_zlib gzip $test] # Save as gzip file set fd [open /tmp/test.gz w] fconfigure $fd -translation binary -encoding binary puts -nonewline $fd $gzip close $fd # Uncompress gzipped file set test [ns_zlib gunzip /tmp/test.gz] --> returns "This is test string"


ns_adp_ctl(n), load(n)


GZIP, compress, uncompress

4.5 AOLserver