| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\ZlibException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Incrementally deflates data in the specified context. |
| 9 |
* |
| 10 |
* @param resource $context A context created with deflate_init. |
| 11 |
* @param string $data A chunk of data to compress. |
| 12 |
* @param int $flush_mode One of ZLIB_BLOCK, |
| 13 |
* ZLIB_NO_FLUSH, |
| 14 |
* ZLIB_PARTIAL_FLUSH, |
| 15 |
* ZLIB_SYNC_FLUSH (default), |
| 16 |
* ZLIB_FULL_FLUSH, ZLIB_FINISH. |
| 17 |
* Normally you will want to set ZLIB_NO_FLUSH to |
| 18 |
* maximize compression, and ZLIB_FINISH to terminate |
| 19 |
* with the last chunk of data. See the zlib manual for a |
| 20 |
* detailed description of these constants. |
| 21 |
* @return string Returns a chunk of compressed data. |
| 22 |
* @throws ZlibException |
| 23 |
* |
| 24 |
*/ |
| 25 |
function deflate_add($context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string |
| 26 |
{ |
| 27 |
error_clear_last(); |
| 28 |
$result = \deflate_add($context, $data, $flush_mode); |
| 29 |
if ($result === false) { |
| 30 |
throw ZlibException::createFromPhpError(); |
| 31 |
} |
| 32 |
return $result; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* Initializes an incremental deflate context using the specified |
| 38 |
* encoding. |
| 39 |
* |
| 40 |
* Note that the window option here only sets the window size |
| 41 |
* of the algorithm, differently from the zlib filters where the same parameter |
| 42 |
* also sets the encoding to use; the encoding must be set with the |
| 43 |
* encoding parameter. |
| 44 |
* |
| 45 |
* Limitation: there is currently no way to set the header information on a GZIP |
| 46 |
* compressed stream, which are set as follows: GZIP signature |
| 47 |
* (\x1f\x8B); compression method (\x08 |
| 48 |
* == DEFLATE); 6 zero bytes; the operating system set to the current system |
| 49 |
* (\x00 = Windows, \x03 = Unix, etc.) |
| 50 |
* |
| 51 |
* @param int $encoding One of the ZLIB_ENCODING_* constants. |
| 52 |
* @param array|null $options An associative array which may contain the following elements: |
| 53 |
* |
| 54 |
* |
| 55 |
* level |
| 56 |
* |
| 57 |
* |
| 58 |
* The compression level in range -1..9; defaults to -1. |
| 59 |
* |
| 60 |
* |
| 61 |
* |
| 62 |
* |
| 63 |
* memory |
| 64 |
* |
| 65 |
* |
| 66 |
* The compression memory level in range 1..9; defaults to 8. |
| 67 |
* |
| 68 |
* |
| 69 |
* |
| 70 |
* |
| 71 |
* window |
| 72 |
* |
| 73 |
* |
| 74 |
* The zlib window size (logarithmic) in range 8..15; defaults to 15. |
| 75 |
* |
| 76 |
* |
| 77 |
* |
| 78 |
* |
| 79 |
* strategy |
| 80 |
* |
| 81 |
* |
| 82 |
* One of ZLIB_FILTERED, |
| 83 |
* ZLIB_HUFFMAN_ONLY, ZLIB_RLE, |
| 84 |
* ZLIB_FIXED or |
| 85 |
* ZLIB_DEFAULT_STRATEGY (the default). |
| 86 |
* |
| 87 |
* |
| 88 |
* |
| 89 |
* |
| 90 |
* dictionary |
| 91 |
* |
| 92 |
* |
| 93 |
* A string or an array of strings |
| 94 |
* of the preset dictionary (default: no preset dictionary). |
| 95 |
* |
| 96 |
* |
| 97 |
* |
| 98 |
* |
| 99 |
* |
| 100 |
* The compression level in range -1..9; defaults to -1. |
| 101 |
* |
| 102 |
* The compression memory level in range 1..9; defaults to 8. |
| 103 |
* |
| 104 |
* The zlib window size (logarithmic) in range 8..15; defaults to 15. |
| 105 |
* |
| 106 |
* One of ZLIB_FILTERED, |
| 107 |
* ZLIB_HUFFMAN_ONLY, ZLIB_RLE, |
| 108 |
* ZLIB_FIXED or |
| 109 |
* ZLIB_DEFAULT_STRATEGY (the default). |
| 110 |
* |
| 111 |
* A string or an array of strings |
| 112 |
* of the preset dictionary (default: no preset dictionary). |
| 113 |
* |
| 114 |
* @return resource Returns a deflate context resource (zlib.deflate) on |
| 115 |
* success. |
| 116 |
* @throws ZlibException |
| 117 |
* |
| 118 |
*/ |
| 119 |
function deflate_init(int $encoding, ?array $options = null) |
| 120 |
{ |
| 121 |
error_clear_last(); |
| 122 |
$result = \deflate_init($encoding, $options); |
| 123 |
if ($result === false) { |
| 124 |
throw ZlibException::createFromPhpError(); |
| 125 |
} |
| 126 |
return $result; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
/** |
| 131 |
* Closes the given gz-file pointer. |
| 132 |
* |
| 133 |
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
| 134 |
* successfully opened by gzopen. |
| 135 |
* @throws ZlibException |
| 136 |
* |
| 137 |
*/ |
| 138 |
function gzclose($zp): void |
| 139 |
{ |
| 140 |
error_clear_last(); |
| 141 |
$result = \gzclose($zp); |
| 142 |
if ($result === false) { |
| 143 |
throw ZlibException::createFromPhpError(); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
* This function compresses the given string using the ZLIB |
| 150 |
* data format. |
| 151 |
* |
| 152 |
* For details on the ZLIB compression algorithm see the document |
| 153 |
* "ZLIB Compressed Data Format |
| 154 |
* Specification version 3.3" (RFC 1950). |
| 155 |
* |
| 156 |
* @param string $data The data to compress. |
| 157 |
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
| 158 |
* for maximum compression. |
| 159 |
* |
| 160 |
* If -1 is used, the default compression of the zlib library is used which is 6. |
| 161 |
* @param int $encoding One of ZLIB_ENCODING_* constants. |
| 162 |
* @return string The compressed string. |
| 163 |
* @throws ZlibException |
| 164 |
* |
| 165 |
*/ |
| 166 |
function gzcompress(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_DEFLATE): string |
| 167 |
{ |
| 168 |
error_clear_last(); |
| 169 |
$result = \gzcompress($data, $level, $encoding); |
| 170 |
if ($result === false) { |
| 171 |
throw ZlibException::createFromPhpError(); |
| 172 |
} |
| 173 |
return $result; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
/** |
| 178 |
* This function returns a decoded version of the input |
| 179 |
* data. |
| 180 |
* |
| 181 |
* @param string $data The data to decode, encoded by gzencode. |
| 182 |
* @param int|null $length The maximum length of data to decode. |
| 183 |
* |
| 184 |
* @return string The decoded string. |
| 185 |
* @throws ZlibException |
| 186 |
* |
| 187 |
*/ |
| 188 |
function gzdecode(string $data, ?int $length = null): string |
| 189 |
{ |
| 190 |
error_clear_last(); |
| 191 |
if ($length !== null) { |
| 192 |
$result = \gzdecode($data, $length); |
| 193 |
} else { |
| 194 |
$result = \gzdecode($data); |
| 195 |
} |
| 196 |
if ($result === false) { |
| 197 |
throw ZlibException::createFromPhpError(); |
| 198 |
} |
| 199 |
return $result; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
/** |
| 204 |
* This function compresses the given string using the DEFLATE |
| 205 |
* data format. |
| 206 |
* |
| 207 |
* For details on the DEFLATE compression algorithm see the document |
| 208 |
* "DEFLATE Compressed Data Format |
| 209 |
* Specification version 1.3" (RFC 1951). |
| 210 |
* |
| 211 |
* @param string $data The data to deflate. |
| 212 |
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
| 213 |
* for maximum compression. If not given, the default compression level will |
| 214 |
* be the default compression level of the zlib library. |
| 215 |
* @param int $encoding One of ZLIB_ENCODING_* constants. |
| 216 |
* @return string The deflated string. |
| 217 |
* @throws ZlibException |
| 218 |
* |
| 219 |
*/ |
| 220 |
function gzdeflate(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_RAW): string |
| 221 |
{ |
| 222 |
error_clear_last(); |
| 223 |
$result = \gzdeflate($data, $level, $encoding); |
| 224 |
if ($result === false) { |
| 225 |
throw ZlibException::createFromPhpError(); |
| 226 |
} |
| 227 |
return $result; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/** |
| 232 |
* This function returns a compressed version of the input |
| 233 |
* data compatible with the output of the |
| 234 |
* gzip program. |
| 235 |
* |
| 236 |
* For more information on the GZIP file format, see the document: |
| 237 |
* GZIP file format specification |
| 238 |
* version 4.3 (RFC 1952). |
| 239 |
* |
| 240 |
* @param string $data The data to encode. |
| 241 |
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
| 242 |
* for maximum compression. If not given, the default compression level will |
| 243 |
* be the default compression level of the zlib library. |
| 244 |
* @param int $encoding_mode The encoding mode. Can be FORCE_GZIP (the default) |
| 245 |
* or FORCE_DEFLATE. |
| 246 |
* |
| 247 |
* Prior to PHP 5.4.0, using FORCE_DEFLATE results in |
| 248 |
* a standard zlib deflated string (inclusive zlib headers) after a gzip |
| 249 |
* file header but without the trailing crc32 checksum. |
| 250 |
* |
| 251 |
* In PHP 5.4.0 and later, FORCE_DEFLATE generates |
| 252 |
* RFC 1950 compliant output, consisting of a zlib header, the deflated |
| 253 |
* data, and an Adler checksum. |
| 254 |
* @return string The encoded string. |
| 255 |
* @throws ZlibException |
| 256 |
* |
| 257 |
*/ |
| 258 |
function gzencode(string $data, int $level = -1, int $encoding_mode = FORCE_GZIP): string |
| 259 |
{ |
| 260 |
error_clear_last(); |
| 261 |
$result = \gzencode($data, $level, $encoding_mode); |
| 262 |
if ($result === false) { |
| 263 |
throw ZlibException::createFromPhpError(); |
| 264 |
} |
| 265 |
return $result; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
/** |
| 270 |
* Gets a (uncompressed) string of up to length - 1 bytes read from the given |
| 271 |
* file pointer. Reading ends when length - 1 bytes have been read, on a |
| 272 |
* newline, or on EOF (whichever comes first). |
| 273 |
* |
| 274 |
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
| 275 |
* successfully opened by gzopen. |
| 276 |
* @param int|null $length The length of data to get. |
| 277 |
* |
| 278 |
* @return string The uncompressed string. |
| 279 |
* @throws ZlibException |
| 280 |
* |
| 281 |
*/ |
| 282 |
function gzgets($zp, ?int $length = null): string |
| 283 |
{ |
| 284 |
error_clear_last(); |
| 285 |
if ($length !== null) { |
| 286 |
$result = \gzgets($zp, $length); |
| 287 |
} else { |
| 288 |
$result = \gzgets($zp); |
| 289 |
} |
| 290 |
if ($result === false) { |
| 291 |
throw ZlibException::createFromPhpError(); |
| 292 |
} |
| 293 |
return $result; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
/** |
| 298 |
* Identical to gzgets, except that |
| 299 |
* gzgetss attempts to strip any HTML and PHP |
| 300 |
* tags from the text it reads. |
| 301 |
* |
| 302 |
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
| 303 |
* successfully opened by gzopen. |
| 304 |
* @param int $length The length of data to get. |
| 305 |
* @param string|null $allowable_tags You can use this optional parameter to specify tags which should not |
| 306 |
* be stripped. |
| 307 |
* |
| 308 |
* @return string The uncompressed and stripped string. |
| 309 |
* @throws ZlibException |
| 310 |
* |
| 311 |
*/ |
| 312 |
function gzgetss($zp, int $length, ?string $allowable_tags = null): string |
| 313 |
{ |
| 314 |
error_clear_last(); |
| 315 |
if ($allowable_tags !== null) { |
| 316 |
$result = \gzgetss($zp, $length, $allowable_tags); |
| 317 |
} else { |
| 318 |
$result = \gzgetss($zp, $length); |
| 319 |
} |
| 320 |
if ($result === false) { |
| 321 |
throw ZlibException::createFromPhpError(); |
| 322 |
} |
| 323 |
return $result; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
/** |
| 328 |
* This function inflates a deflated string. |
| 329 |
* |
| 330 |
* @param string $data The data compressed by gzdeflate. |
| 331 |
* @param int $length The maximum length of data to decode. |
| 332 |
* @return string The original uncompressed data. |
| 333 |
* |
| 334 |
* The function will return an error if the uncompressed data is more than |
| 335 |
* 32768 times the length of the compressed input data |
| 336 |
* or more than the optional parameter length. |
| 337 |
* @throws ZlibException |
| 338 |
* |
| 339 |
*/ |
| 340 |
function gzinflate(string $data, int $length = 0): string |
| 341 |
{ |
| 342 |
error_clear_last(); |
| 343 |
$result = \gzinflate($data, $length); |
| 344 |
if ($result === false) { |
| 345 |
throw ZlibException::createFromPhpError(); |
| 346 |
} |
| 347 |
return $result; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
/** |
| 352 |
* Reads to EOF on the given gz-file pointer from the current position and |
| 353 |
* writes the (uncompressed) results to standard output. |
| 354 |
* |
| 355 |
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
| 356 |
* successfully opened by gzopen. |
| 357 |
* @return int The number of uncompressed characters read from gz |
| 358 |
* and passed through to the input. |
| 359 |
* @throws ZlibException |
| 360 |
* |
| 361 |
*/ |
| 362 |
function gzpassthru($zp): int |
| 363 |
{ |
| 364 |
error_clear_last(); |
| 365 |
$result = \gzpassthru($zp); |
| 366 |
if ($result === false) { |
| 367 |
throw ZlibException::createFromPhpError(); |
| 368 |
} |
| 369 |
return $result; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
/** |
| 374 |
* Sets the file position indicator of the given gz-file pointer to the |
| 375 |
* beginning of the file stream. |
| 376 |
* |
| 377 |
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
| 378 |
* successfully opened by gzopen. |
| 379 |
* @throws ZlibException |
| 380 |
* |
| 381 |
*/ |
| 382 |
function gzrewind($zp): void |
| 383 |
{ |
| 384 |
error_clear_last(); |
| 385 |
$result = \gzrewind($zp); |
| 386 |
if ($result === false) { |
| 387 |
throw ZlibException::createFromPhpError(); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
/** |
| 393 |
* This function uncompress a compressed string. |
| 394 |
* |
| 395 |
* @param string $data The data compressed by gzcompress. |
| 396 |
* @param int $length The maximum length of data to decode. |
| 397 |
* @return string The original uncompressed data. |
| 398 |
* |
| 399 |
* The function will return an error if the uncompressed data is more than |
| 400 |
* 32768 times the length of the compressed input data |
| 401 |
* or more than the optional parameter length. |
| 402 |
* @throws ZlibException |
| 403 |
* |
| 404 |
*/ |
| 405 |
function gzuncompress(string $data, int $length = 0): string |
| 406 |
{ |
| 407 |
error_clear_last(); |
| 408 |
$result = \gzuncompress($data, $length); |
| 409 |
if ($result === false) { |
| 410 |
throw ZlibException::createFromPhpError(); |
| 411 |
} |
| 412 |
return $result; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
/** |
| 417 |
* |
| 418 |
* |
| 419 |
* @param resource $resource |
| 420 |
* @return int Returns number of bytes read so far. |
| 421 |
* @throws ZlibException |
| 422 |
* |
| 423 |
*/ |
| 424 |
function inflate_get_read_len($resource): int |
| 425 |
{ |
| 426 |
error_clear_last(); |
| 427 |
$result = \inflate_get_read_len($resource); |
| 428 |
if ($result === false) { |
| 429 |
throw ZlibException::createFromPhpError(); |
| 430 |
} |
| 431 |
return $result; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
/** |
| 436 |
* Usually returns either ZLIB_OK or ZLIB_STREAM_END. |
| 437 |
* |
| 438 |
* @param resource $resource |
| 439 |
* @return int Returns decompression status. |
| 440 |
* @throws ZlibException |
| 441 |
* |
| 442 |
*/ |
| 443 |
function inflate_get_status($resource): int |
| 444 |
{ |
| 445 |
error_clear_last(); |
| 446 |
$result = \inflate_get_status($resource); |
| 447 |
if ($result === false) { |
| 448 |
throw ZlibException::createFromPhpError(); |
| 449 |
} |
| 450 |
return $result; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
/** |
| 455 |
* Incrementally inflates encoded data in the specified context. |
| 456 |
* |
| 457 |
* Limitation: header information from GZIP compressed data are not made |
| 458 |
* available. |
| 459 |
* |
| 460 |
* @param resource $context A context created with inflate_init. |
| 461 |
* @param string $encoded_data A chunk of compressed data. |
| 462 |
* @param int $flush_mode One of ZLIB_BLOCK, |
| 463 |
* ZLIB_NO_FLUSH, |
| 464 |
* ZLIB_PARTIAL_FLUSH, |
| 465 |
* ZLIB_SYNC_FLUSH (default), |
| 466 |
* ZLIB_FULL_FLUSH, ZLIB_FINISH. |
| 467 |
* Normally you will want to set ZLIB_NO_FLUSH to |
| 468 |
* maximize compression, and ZLIB_FINISH to terminate |
| 469 |
* with the last chunk of data. See the zlib manual for a |
| 470 |
* detailed description of these constants. |
| 471 |
* @return string Returns a chunk of uncompressed data. |
| 472 |
* @throws ZlibException |
| 473 |
* |
| 474 |
*/ |
| 475 |
function inflate_add($context, string $encoded_data, int $flush_mode = ZLIB_SYNC_FLUSH): string |
| 476 |
{ |
| 477 |
error_clear_last(); |
| 478 |
$result = \inflate_add($context, $encoded_data, $flush_mode); |
| 479 |
if ($result === false) { |
| 480 |
throw ZlibException::createFromPhpError(); |
| 481 |
} |
| 482 |
return $result; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
/** |
| 487 |
* Initialize an incremental inflate context with the specified |
| 488 |
* encoding. |
| 489 |
* |
| 490 |
* @param int $encoding One of the ZLIB_ENCODING_* constants. |
| 491 |
* @param array|null $options An associative array which may contain the following elements: |
| 492 |
* |
| 493 |
* |
| 494 |
* level |
| 495 |
* |
| 496 |
* |
| 497 |
* The compression level in range -1..9; defaults to -1. |
| 498 |
* |
| 499 |
* |
| 500 |
* |
| 501 |
* |
| 502 |
* memory |
| 503 |
* |
| 504 |
* |
| 505 |
* The compression memory level in range 1..9; defaults to 8. |
| 506 |
* |
| 507 |
* |
| 508 |
* |
| 509 |
* |
| 510 |
* window |
| 511 |
* |
| 512 |
* |
| 513 |
* The zlib window size (logarithmic) in range 8..15; defaults to 15. |
| 514 |
* |
| 515 |
* |
| 516 |
* |
| 517 |
* |
| 518 |
* strategy |
| 519 |
* |
| 520 |
* |
| 521 |
* One of ZLIB_FILTERED, |
| 522 |
* ZLIB_HUFFMAN_ONLY, ZLIB_RLE, |
| 523 |
* ZLIB_FIXED or |
| 524 |
* ZLIB_DEFAULT_STRATEGY (the default). |
| 525 |
* |
| 526 |
* |
| 527 |
* |
| 528 |
* |
| 529 |
* dictionary |
| 530 |
* |
| 531 |
* |
| 532 |
* A string or an array of strings |
| 533 |
* of the preset dictionary (default: no preset dictionary). |
| 534 |
* |
| 535 |
* |
| 536 |
* |
| 537 |
* |
| 538 |
* |
| 539 |
* The compression level in range -1..9; defaults to -1. |
| 540 |
* |
| 541 |
* The compression memory level in range 1..9; defaults to 8. |
| 542 |
* |
| 543 |
* The zlib window size (logarithmic) in range 8..15; defaults to 15. |
| 544 |
* |
| 545 |
* One of ZLIB_FILTERED, |
| 546 |
* ZLIB_HUFFMAN_ONLY, ZLIB_RLE, |
| 547 |
* ZLIB_FIXED or |
| 548 |
* ZLIB_DEFAULT_STRATEGY (the default). |
| 549 |
* |
| 550 |
* A string or an array of strings |
| 551 |
* of the preset dictionary (default: no preset dictionary). |
| 552 |
* |
| 553 |
* @return resource Returns an inflate context resource (zlib.inflate) on |
| 554 |
* success. |
| 555 |
* @throws ZlibException |
| 556 |
* |
| 557 |
*/ |
| 558 |
function inflate_init(int $encoding, ?array $options = null) |
| 559 |
{ |
| 560 |
error_clear_last(); |
| 561 |
$result = \inflate_init($encoding, $options); |
| 562 |
if ($result === false) { |
| 563 |
throw ZlibException::createFromPhpError(); |
| 564 |
} |
| 565 |
return $result; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
/** |
| 570 |
* Reads a file, decompresses it and writes it to standard output. |
| 571 |
* |
| 572 |
* readgzfile can be used to read a file which is not in |
| 573 |
* gzip format; in this case readgzfile will directly |
| 574 |
* read from the file without decompression. |
| 575 |
* |
| 576 |
* @param string $filename The file name. This file will be opened from the filesystem and its |
| 577 |
* contents written to standard output. |
| 578 |
* @param int $use_include_path You can set this optional parameter to 1, if you |
| 579 |
* want to search for the file in the include_path too. |
| 580 |
* @return int Returns the number of (uncompressed) bytes read from the file on success |
| 581 |
* @throws ZlibException |
| 582 |
* |
| 583 |
*/ |
| 584 |
function readgzfile(string $filename, int $use_include_path = 0): int |
| 585 |
{ |
| 586 |
error_clear_last(); |
| 587 |
$result = \readgzfile($filename, $use_include_path); |
| 588 |
if ($result === false) { |
| 589 |
throw ZlibException::createFromPhpError(); |
| 590 |
} |
| 591 |
return $result; |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
/** |
| 596 |
* Uncompress any raw/gzip/zlib encoded data. |
| 597 |
* |
| 598 |
* @param string $data |
| 599 |
* @param int|null $max_decoded_len |
| 600 |
* |
| 601 |
* @return string Returns the uncompressed data. |
| 602 |
* @throws ZlibException |
| 603 |
* |
| 604 |
*/ |
| 605 |
function zlib_decode(string $data, ?int $max_decoded_len = null): string |
| 606 |
{ |
| 607 |
error_clear_last(); |
| 608 |
if ($max_decoded_len !== null) { |
| 609 |
$result = \zlib_decode($data, $max_decoded_len); |
| 610 |
} else { |
| 611 |
$result = \zlib_decode($data); |
| 612 |
} |
| 613 |
if ($result === false) { |
| 614 |
throw ZlibException::createFromPhpError(); |
| 615 |
} |
| 616 |
return $result; |
| 617 |
} |
| 618 |
|