| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\Bzip2Exception; |
| 6 |
|
| 7 |
/** |
| 8 |
* Closes the given bzip2 file pointer. |
| 9 |
* |
| 10 |
* @param resource $bz The file pointer. It must be valid and must point to a file |
| 11 |
* successfully opened by bzopen. |
| 12 |
* @throws Bzip2Exception |
| 13 |
* |
| 14 |
*/ |
| 15 |
function bzclose($bz): void |
| 16 |
{ |
| 17 |
error_clear_last(); |
| 18 |
$result = \bzclose($bz); |
| 19 |
if ($result === false) { |
| 20 |
throw Bzip2Exception::createFromPhpError(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Forces a write of all buffered bzip2 data for the file pointer |
| 27 |
* bz. |
| 28 |
* |
| 29 |
* @param resource $bz The file pointer. It must be valid and must point to a file |
| 30 |
* successfully opened by bzopen. |
| 31 |
* @throws Bzip2Exception |
| 32 |
* |
| 33 |
*/ |
| 34 |
function bzflush($bz): void |
| 35 |
{ |
| 36 |
error_clear_last(); |
| 37 |
$result = \bzflush($bz); |
| 38 |
if ($result === false) { |
| 39 |
throw Bzip2Exception::createFromPhpError(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* bzread reads from the given bzip2 file pointer. |
| 46 |
* |
| 47 |
* Reading stops when length (uncompressed) bytes have |
| 48 |
* been read or EOF is reached, whichever comes first. |
| 49 |
* |
| 50 |
* @param resource $bz The file pointer. It must be valid and must point to a file |
| 51 |
* successfully opened by bzopen. |
| 52 |
* @param int $length If not specified, bzread will read 1024 |
| 53 |
* (uncompressed) bytes at a time. A maximum of 8192 |
| 54 |
* uncompressed bytes will be read at a time. |
| 55 |
* @return string Returns the uncompressed data. |
| 56 |
* @throws Bzip2Exception |
| 57 |
* |
| 58 |
*/ |
| 59 |
function bzread($bz, int $length = 1024): string |
| 60 |
{ |
| 61 |
error_clear_last(); |
| 62 |
$result = \bzread($bz, $length); |
| 63 |
if ($result === false) { |
| 64 |
throw Bzip2Exception::createFromPhpError(); |
| 65 |
} |
| 66 |
return $result; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* bzwrite writes a string into the given bzip2 file |
| 72 |
* stream. |
| 73 |
* |
| 74 |
* @param resource $bz The file pointer. It must be valid and must point to a file |
| 75 |
* successfully opened by bzopen. |
| 76 |
* @param string $data The written data. |
| 77 |
* @param int|null $length If supplied, writing will stop after length |
| 78 |
* (uncompressed) bytes have been written or the end of |
| 79 |
* data is reached, whichever comes first. |
| 80 |
* |
| 81 |
* @return int Returns the number of bytes written. |
| 82 |
* @throws Bzip2Exception |
| 83 |
* |
| 84 |
*/ |
| 85 |
function bzwrite($bz, string $data, ?int $length = null): int |
| 86 |
{ |
| 87 |
error_clear_last(); |
| 88 |
if ($length !== null) { |
| 89 |
$result = \bzwrite($bz, $data, $length); |
| 90 |
} else { |
| 91 |
$result = \bzwrite($bz, $data); |
| 92 |
} |
| 93 |
if ($result === false) { |
| 94 |
throw Bzip2Exception::createFromPhpError(); |
| 95 |
} |
| 96 |
return $result; |
| 97 |
} |
| 98 |
|