This section documents functions for compressing and uncompressing data.
Uncompresses the given data with the bzip2 algorithm and returns the uncompressed data as a binary.
binary bunzip2_to_binary(binary $bin)
$bin = bunzip2_to_binary($data);
Table 3.329. Exceptions Thrown by bunzip2_to_binary()
err | desc |
|---|---|
| bzlib returned an error while processing. |
Uncompresses the given data with the bzip2 algorithm and returns the uncompressed data as a string. An optional second string argument may be passed to give the character encoding of the string; if not present, the default character encoding for the process is assumed.
string bunzip2_to_string(binary $bin, string $encoding = defaultEncoding)
$str = bunzip2_to_string($bzip2_string);
Table 3.330. Arguments and Return Values for bunzip2_to_string()
Argument Type | Return Type | Description |
|---|---|---|
Uncompresses the input data and returns a string. The optional second argument sets the string |
Table 3.331. Exceptions Thrown by bunzip_to_string()
err | desc |
|---|---|
| bzlib returned an error while processing. |
Compresses the given data with the bzip2 algorithm and returns the uncompressed data as a binary. The optional second argument specifies the compression level; if no second argument is given, a value of 9 is used, taking the most memory and proving the best compression ratio. The second argument if given must be a value from 1 - 9. Note that strings are compressed without the trailing null character.
binary bzip2(data $bin, softint $level = 9)
$bin = compress("hello");
Table 3.332. Arguments and Return Values for bzip2()
Argument Type | Return Type | Description |
|---|---|---|
Compresses the input data and returns a binary object. The optional |
Table 3.333. Exceptions Thrown by bzip2()
err | desc |
|---|---|
| The bzip2 library reported an error while performing the compression. |
| The level argument was not between 1 and 9 inclusive. |
Performs zlib-based "deflate" data compression (RFC 1951) and returns a binary object of the compressed data. The optional second argument specifies the compression level; if no second argument is given, then a tradeoff between speed and compression size is taken (default: Z_DEFAULT_COMPRESSION, meaning to let zlib use its default compression ratio). Note that strings are compressed without the trailing null character.
binary compress(data $bin, softint $level = Z_DEFAULT_COMPRESSION)
$bin = compress("hello");
Table 3.334. Arguments and Return Values for compress()
Argument Type | Return Type | Description |
|---|---|---|
Compresses the input data and returns a binary object. The optional |
Table 3.335. Exceptions Thrown by compress()
err | desc |
|---|---|
| the compression level is invalid (must be between 1 - 9 inclusive). |
| zlib returned an error while processing. |
Uncompresses gzipped data using zlib functions and returns a binary object of the uncompressed data.
binary gunzip_to_binary(binary $bin)
$bin = gunzip_to_binary($data);
Table 3.337. Exceptions Thrown by gunzip_to_binary()
err | desc |
|---|---|
| zlib returned an error while processing. |
Uncompresses gzipped data using zlib functions and returns a string of the uncompressed data. An optional second string argument may be passed to give the character encoding of the string; if not present, the default character encoding for the process is assumed.
string gunzip_to_string(binary $bin)
string gunzip_to_string(binary $bin, string $encoding)
$str = gunzip_to_string($gzipped_string);
Table 3.338. Arguments and Return Values for gunzip_to_string()
Argument Type | Return Type | Description |
|---|---|---|
Uncompresses the input data and returns a string. The optional second argument sets the string |
Table 3.339. Exceptions Thrown by gunzip_to_string()
err | desc |
|---|---|
| zlib returned an error while processing. |
Performs zlib-based "gzip" data compression (RFC 1952) and returns a binary object of the compressed data. The optional second argument specifies the compression level between 1 (lowest comperssion level) and 9 (highest compression level); if no second argument is given, then a tradeoff between speed and compression size is taken (default: Z_DEFAULT_COMPRESSION). Note that strings are compressed without the trailing null character.
binary gzip(string $data, softint $level = Z_DEFAULT_COMPRESSION)
$bin = gzip($data);
Table 3.340. Arguments and Return Values for gzip()
Argument Type | Return Type | Description |
|---|---|---|
Compresses the input data and returns a binary object of the gzipped data. The optional |
Table 3.341. Exceptions Thrown by gzip()
err | desc |
|---|---|
| the compression level is invalid (must be between 1 - 9 inclusive). |
| zlib returned an error while processing. |
Uncompresses data using zlib functions and returns a binary object of the uncompressed data.
binary uncompress_to_binary(binary $bin)
$bin = uncompress_to_binary($compressed_data);
Table 3.343. Exceptions Thrown by uncompress_to_binary()
err | desc |
|---|---|
| zlib returned an error while processing. |
Uncompresses data using zlib functions and returns a string of the uncompressed data. An optional second string argument may be passed to give the character encoding of the string; if not present, the default character encoding for the process is assumed.
string uncompress_to_string(binary $bin)
string uncompress_to_string(binary $bin, string $encoding)
$str = uncompress_to_string($compressed_data);
Table 3.344. Arguments and Return Values for uncompress_to_string()
Argument Type | Return Type | Description |
|---|---|---|
Uncompresses the input data and returns a string. The optional second argument sets the string |
Table 3.345. Exceptions Thrown by uncompress_to_string()
err | desc |
|---|---|
| zlib returned an error while processing. |