dimtrovich /
php-db-dumper
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * This file is part of dimtrovich/db-dumper". |
||||
| 5 | * |
||||
| 6 | * (c) 2024 Dimitri Sitchet Tomkeu <[email protected]> |
||||
| 7 | * |
||||
| 8 | * For the full copyright and license information, please view |
||||
| 9 | * the LICENSE file that was distributed with this source code. |
||||
| 10 | */ |
||||
| 11 | |||||
| 12 | namespace Dimtrovich\DbDumper\Compressor; |
||||
| 13 | |||||
| 14 | use Dimtrovich\DbDumper\Exceptions\Exception; |
||||
| 15 | |||||
| 16 | class Bzip2Compressor extends Factory |
||||
| 17 | { |
||||
| 18 | /** |
||||
| 19 | * @var false|resource |
||||
| 20 | */ |
||||
| 21 | private $handler; |
||||
| 22 | |||||
| 23 | public function __construct() |
||||
| 24 | { |
||||
| 25 | if (! function_exists('bzopen')) { |
||||
| 26 | 2 | throw Exception::compressionDriverMissing('bzip2'); |
|||
| 27 | } |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * {@inheritDoc} |
||||
| 32 | */ |
||||
| 33 | public function open(string $filename, string $mode = 'w'): bool |
||||
| 34 | { |
||||
| 35 | $this->handler = bzopen($filename, $mode); |
||||
| 36 | if (false === $this->handler) { |
||||
| 37 | throw Exception::fileNotWritable($filename); |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | return true; |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * {@inheritDoc} |
||||
| 45 | */ |
||||
| 46 | public function write(string $data): int |
||||
| 47 | { |
||||
| 48 | $bytesWritten = bzwrite($this->handler, $data); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 49 | |||||
| 50 | if (false === $bytesWritten) { |
||||
| 51 | throw Exception::failledToWrite(); |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | return $bytesWritten; |
||||
| 55 | } |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * {@inheritDoc} |
||||
| 59 | */ |
||||
| 60 | public function read(): string |
||||
| 61 | { |
||||
| 62 | return ''; |
||||
| 63 | /* while (!bzeof($this->handler)) { |
||||
| 64 | // Read buffer-size bytes |
||||
| 65 | $content .= bzread($this->handler, 4096); // read 4kb at a time |
||||
| 66 | } */ |
||||
| 67 | } |
||||
| 68 | |||||
| 69 | /** |
||||
| 70 | * {@inheritDoc} |
||||
| 71 | */ |
||||
| 72 | public function close(): bool |
||||
| 73 | { |
||||
| 74 | return bzclose($this->handler); |
||||
|
0 ignored issues
–
show
It seems like
$this->handler can also be of type boolean; however, parameter $bz of bzclose() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 75 | } |
||||
| 76 | } |
||||
| 77 |