The ZLIB_UNCOMPRESS function uncompresses a given input byte array using the DEFLATE compression algorithm, and returns a byte array containing the original uncompressed data. The uncompression is done using the ZLIB library, written by Jean-Loup Gailly and Mark Adler.

If you know the dimensions and data type of the original data, then you can use the DIMENSIONS and TYPE keywords to restore the data to its correct type and shape. Otherwise, IDL will automatically uncompress the data to a one-dimensional byte array containing all of the original uncompressed data.

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_UNCOMPRESS( Array [, /GZIP_HEADER] [, DIMENSIONS=value] [, /NO_HEADER] [, TYPE=value] )

Arguments


Array

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

Keywords


GZIP_HEADER

Set this keyword if the input stream contains a GZIP-style header and trailer, instead of the default ZLIB header/trailer.

Note: IDL uses the uncompressed size stored in the GZIP trailer to allocate an output array of the correct size. The other fields in the GZIP header/trailer are ignored.

DIMENSIONS

Set this keyword to a scalar or array of dimensions for the result. If DIMENSIONS is not specified then a one-dimensional vector array is returned.

Tip: If you know the expected dimensions of the resulting uncompressed data, then it is much more efficient to pass in the DIMENSIONS keyword, even for one-dimensional vector arrays. Otherwise, IDL will need to allocate buffers of increasing size until the entire array can be uncompressed.

Note: To avoid unexpected results, the dimensions specified by the DIMENSIONS keyword should match the original dimensions of the array passed into ZLIB_COMPRESS. IDL will throw an error if the number of elements is not equal to the size of the uncompressed data.

NO_HEADER

Set this keyword if the input stream does not include any header or trailer, instead of the default ZLIB header/trailer.

TYPE

Set this keyword to an integer giving the IDL data type for the result. If TYPE is not specified then an array of type BYTE is returned.

Note: To avoid unexpected results, the type specified by the TYPE keyword should match the original type of the array passed into ZLIB_COMPRESS. IDL will throw an error if the number of uncompressed bytes is not evenly divisible by the size of the data type in bytes.

Version History


8.2.3

Introduced

See Also


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