| Total Complexity | 9 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class GzipCompressor extends Factory |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var false|resource |
||
| 20 | */ |
||
| 21 | private $handler; |
||
| 22 | |||
| 23 | public function __construct() |
||
| 24 | { |
||
| 25 | if (! function_exists('gzopen')) { |
||
| 26 | throw Exception::compressionDriverMissing('gzip'); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritDoc} |
||
| 32 | */ |
||
| 33 | public function open(string $filename, string $mode = 'wb'): bool |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritDoc} |
||
| 45 | */ |
||
| 46 | public function write(string $data): int |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritDoc} |
||
| 59 | */ |
||
| 60 | public function read(): string |
||
| 61 | { |
||
| 62 | $content = ''; |
||
| 63 | |||
| 64 | while (! gzeof($this->handler)) { |
||
| 65 | // Read buffer-size bytes |
||
| 66 | $content .= gzread($this->handler, 4096); // read 4kb at a time |
||
| 67 | } |
||
| 68 | |||
| 69 | return $content; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritDoc} |
||
| 74 | */ |
||
| 75 | public function close(): bool |
||
| 78 | } |
||
| 79 | } |
||
| 80 |