The ZLIB_COMPRESS function compresses a given input array using the DEFLATE compression algorithm, and returns a byte array containing the compressed data, along with a header and trailer describing the compressed data. The compression is done using the ZLIB library, written by Jean-Loup Gailly and Mark Adler.

The compressed data can be uncompressed using the ZLIB_UNCOMPRESS function.

Examples


Here, we compress and uncompress a float array:

data = FINDGEN(100, 200)
zdata = ZLIB_COMPRESS(data)
HELP, zdata
dataout = ZLIB_UNCOMPRESS(zdata, TYPE=4, DIMENSIONS=[100, 200])
PRINT, ARRAY_EQUAL(dataout, data)

IDL prints:

ZDATA           BYTE      = Array[23379]
  1

Since the float array has a total of 80,000 bytes, the compression space savings is 71%.

Syntax


Result = ZLIB_COMPRESS( Array [, /GZIP_HEADER] [, LEVEL=value] [, /NO_HEADER] )

Arguments


Array

Set this argument to an array of any IDL numeric type.

Keywords


GZIP_HEADER

Set this keyword to output the results using a GZIP-style header and trailer, instead of the default ZLIB header/trailer. In this case, the resulting array could be written out to a disk file which would be fully compatible with the GZIP file format.

Tip: Unlike the default ZLIB header/trailer, the GZIP trailer has a field containing the uncompressed data size. Therefore, when ZLIB_UNCOMPRESS is called, IDL will be able to immediately allocate an output array of the correct size, which can significantly reduce memory overhead.

Note: If you set /GZIP_HEADER in ZLIB_COMPRESS, you must set /GZIP_HEADER when calling ZLIB_UNCOMPRESS on the compressed stream.

LEVEL

Set this keyword to an integer in the range 0-9 giving the desired compression level. A value of LEVEL=0 gives no compression, while LEVEL=9 gives the highest compression. Higher values for LEVEL will result in better compression ratios but slower compress and uncompress speeds. The default is LEVEL=6, which is a good compromise between compression and speed. Note that for low compression levels (or highly-random data), the size of the compressed result may be larger than the original data.

NO_HEADER

Set this keyword to not include any header or trailer, instead of the default ZLIB header/trailer.

Note: If you set /NO_HEADER in ZLIB_COMPRESS, you must set /NO_HEADER when calling ZLIB_UNCOMPRESS on the compressed stream.

Version History


8.2.3

Introduced

See Also


FILE_GZIP, FILE_GUNZIP, FILE_TAR, FILE_UNTAR, FILE_ZIP, FILE_UNZIP, OPEN, ZLIB_UNCOMPRESS