This section documents functions for compressing and uncompressing data.
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: 6). Note that strings are compressed without the trailing null character.
compress(string | binary, [level]
)
$bin = compress("hello");
Table 3.288. Arguments and Return Values for compress()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Compresses the input data and returns a binary object. The optional |
Table 3.289. 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.
gunzip_to_binary(binary
)
$bin = gunzip_to_binary($data);
Table 3.290. Arguments and Return Values for gunzip_to_binary()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a binary object. |
Table 3.291. 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.
gunzip_to_string(binary, [encoding]
)
$str = gunzip_to_string($gzipped_string);
Table 3.292. Arguments and Return Values for gunzip_to_string()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a string. The optional |
Table 3.293. 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; if no second argument is given, then a tradeoff between speed and compression size is taken (default: 6). Note that strings are compressed without the trailing null character.
gzip(string | binary, [level]
)
$bin = gzip($data);
Table 3.294. Arguments and Return Values for gzip()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Compresses the input data and returns a binary object of the gzipped data. The optional |
Table 3.295. 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 compressed with bzip2 and returns a binary object of the uncompressed data.
bunzip2_to_binary(binary
)
$bin = bunzip2_to_binary($data);
Table 3.296. Arguments and Return Values for bunzip2_to_binary()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a binary object. |
Table 3.297. Exceptions Thrown by bunzip2_to_binary()
err | desc |
---|---|
| libbz2 returned an error while processing. |
Uncompresses data compressed with bzip2 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.
bunzip2_to_string(binary, [encoding]
)
$str = bunzip2_to_string($gzipped_string);
Table 3.298. Arguments and Return Values for bunzip2_to_string()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a string. The optional |
Table 3.299. Exceptions Thrown by bunzip2_to_string()
err | desc |
---|---|
| libbz2 returned an error while processing. |
Performs "bzip2" data compression and returns a binary object of the compressed data. The optional second argument specifies the compression buffer size as an argument from 1 - 9; if no second argument is given, then the maximum buffer size is assumed (default: 9). Note that strings are compressed without the trailing null character.
bzip2(string | binary, [level]
)
$bin = bzip2($data);
Table 3.300. Arguments and Return Values for bzip2()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Compresses the input data and returns a binary object of the bzip2 data. The optional |
Table 3.301. Exceptions Thrown by bzip2()
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.
uncompress_to_binary(binary
)
$bin = uncompress_to_binary($compressed_data);
Table 3.302. Arguments and Return Values for uncompress_to_binary()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a binary object. |
Table 3.303. 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.
uncompress_to_string(binary, [encoding]
)
$str = uncompress_to_string($compressed_data);
Table 3.304. Arguments and Return Values for uncompress_to_string()
Argument Type | Return Type | Description |
---|---|---|
| Binary | Uncompresses the input data and returns a string. The optional |
Table 3.305. Exceptions Thrown by uncompress_to_string()
err | desc |
---|---|
| zlib returned an error while processing. |