en fr

Disponible uniquement en anglais

Sysquake Pro – Table of Contents

Sysquake – Table of Contents

Sysquake for LaTeX – Table of Contents

ZLib

This section describes functions which compress and uncompress sequences of bytes, such as text. Often, these sequences present redundancy which can be removed to produce a shorter sequence, while still being able to revert to the initial one.

The ZLib extension is based on zlib by J.L. Gailly and M. Adler, whose work is gratefully acknowledged. To preserve their terminology, compression is performed with function deflate, and uncompression with inflate. Compressed data use the zlib or gzip format.

Functions

deflate

Compress a sequence of bytes (zlib format).

Syntax

strc = deflate(str)

Description

deflate(str) produces a string strc which is usually shorter than it argument str. String str can be reconstructed with inflate using only strc. deflate and inflate process any sequence of bytes (8-bit words); their input argument can be any array. However, their shape and their type are lost (the result of deflate and inflate is always a row vector of uint8 if the input is an integer array, or a string if the input is a string) and their elements are restored modulo 256.

Depending on the data, compression rates of 2 or more are typical. Sequences without redundancy (such as random numbers or the result of deflate) can produce a result slightly larger than the initial sequence.

deflate uses the deflate algorithm and the zlib format.

Examples

str = repmat('abcd ef ', 1, 1000);
length(str)
  8000
strc = deflate(str);
length(strc)
  43
str = repmat('abcd ef ', 1, 1000);
strc = deflate(str);
str2 = inflate(strc);
str === str2
  true

To compress objects which are not sequence of bytes, you can use dumpvar and str2obj to convert them to and from a textual representation:

A = repmat(600, 2, 2)
  A =
    600  600
    600  600
inflate(deflate(A))
  1x4 uint8 array
    88  88  88  88
str = dumpvar(A);
str2obj(deflate(inflate(str)))
  600  600
  600  600

See also

inflate, gzip, zwrite

gzip

Compress a sequence of bytes (gzip format).

Syntax

strc = gzip(str)

Description

gzip(str) produces a string strc which is usually shorter than it argument str. String str can be reconstructed with inflate using only strc. gzip and inflate process any sequence of bytes (8-bit words); their input argument can be any array. However, their shape and their type are lost (the result of gzip and inflate is always a row vector of uint8 if the input is an integer array, or a string if the input is a string) and their elements are restored modulo 256.

Depending on the data, compression rates of 2 or more are typical. Sequences without redundancy (such as random numbers or the result of gzip) can produce a result slightly larger than the initial sequence.

gzip uses the deflate algorithm and the gzip format.

Example

str = repmat('abcd ef ', 1, 1000);
length(str)
  8000
strc = gzip(str);
length(strc)
  55
str = repmat('abcd ef ', 1, 1000);
strc = gzip(str);
str2 = inflate(strc);
str === str2
  true

See also

inflate, deflate, gzwrite

gzwrite

Compress a sequence of bytes and write the result with gzip format.

Syntax

nout = gzwrite(fd, data)

Description

gzwrite(fd, data) compresses the array data, of type int8 or uint8, and writes the result to the file descriptor fd with gzip format.

Note that you must write a whole segment of data with one call. Deflation is restarted every time gzwrite is called.

See also

zread, gzip, zwrite

inflate

Uncompress the result of deflate or gzip.

Syntax

str = inflate(strc)

Description

inflate(strc) uncompresses strc to undo the effect of deflate or gzip. If the input is a string, the output is a string whose characters are coded on one byte; if the input is an integer array, the result is a uint8 row vector.

See also

deflate, gzip, zread

zread

Read deflated or gzipped data and uncompress them.

Syntax

(data, nin) = zread(fd, n)
(data, nin) = zread(fd)

Description

zread(fd, n) reads up to n bytes from file descriptor fd, uncompresses them using the inflate algorithm, and returns the result as a row vector of type uint8. An optional second output argument is set to the number of bytes which have actually been read; it is less than n if the end-of-file is reached.

With a single input argument, zread(fd) reads data until the end of the file.

Note that you must read a whole segment of deflated data with one call. Inflation is restarted every time zread is called. Compressed data can have either the zlib or gzip format.

See also

zwrite, inflate

zwrite

Compress a sequence of bytes and write the result with zlib format.

Syntax

nout = zwrite(fd, data)

Description

zwrite(fd, data) compresses the array data, of type int8 or uint8, and writes the result to the file descriptor fd with zlib format.

Note that you must write a whole segment of data with one call. Deflation is restarted every time zwrite is called.

See also

zread, deflate, gzwrite