---
name: "ns_zlib"
section: "3aolserver"
platform: "linux"
package: "aolserver4-dev"
version: "4.5.1-18.1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/ns_zlib"
---

# ns\_zlib(3aolserver)

Zlib compression support

```

```

## NAME

ns\_zlib - Zlib compression support

## SYNOPSIS

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

```

```

## DESCRIPTION

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

- **ns\_zlib compress** *string*

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

- **ns\_zlib gunzip** *file*

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

- **ns\_zlib gzipfile** *file*

  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.

- **ns\_zlib uncompress** *bytearray*

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

## EXAMPLES

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"
```

## SEE ALSO

ns\_adp\_ctl(n), [load(n)](/load/n.md)

## KEYWORDS

GZIP, compress, uncompress
