| Total Complexity | 8 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | 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); |
||
|
|
|||
| 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 |
||
| 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 |
||
| 77 |