* Writes a block of data to the AvroIO object container. */
()
| 183 | * Writes a block of data to the AvroIO object container. |
| 184 | */ |
| 185 | private function writeBlock() |
| 186 | { |
| 187 | if ($this->block_count > 0) { |
| 188 | $this->encoder->writeLong($this->block_count); |
| 189 | $to_write = (string) $this->buffer; |
| 190 | |
| 191 | if ($this->codec === AvroDataIO::DEFLATE_CODEC) { |
| 192 | $to_write = gzdeflate($to_write); |
| 193 | } elseif ($this->codec === AvroDataIO::ZSTANDARD_CODEC) { |
| 194 | if (!extension_loaded('zstd')) { |
| 195 | throw new AvroException('Please install ext-zstd to use zstandard compression.'); |
| 196 | } |
| 197 | $to_write = zstd_compress($to_write); |
| 198 | } elseif ($this->codec === AvroDataIO::SNAPPY_CODEC) { |
| 199 | if (!extension_loaded('snappy')) { |
| 200 | throw new AvroException('Please install ext-snappy to use snappy compression.'); |
| 201 | } |
| 202 | $crc32 = crc32($to_write); |
| 203 | $compressed = snappy_compress($to_write); |
| 204 | $to_write = pack('a*N', $compressed, $crc32); |
| 205 | } elseif ($this->codec === AvroDataIO::BZIP2_CODEC) { |
| 206 | if (!extension_loaded('bz2')) { |
| 207 | throw new AvroException('Please install ext-bz2 to use bzip2 compression.'); |
| 208 | } |
| 209 | $to_write = bzcompress($to_write); |
| 210 | } |
| 211 | |
| 212 | $this->encoder->writeLong(strlen($to_write)); |
| 213 | $this->write($to_write); |
| 214 | $this->write($this->sync_marker); |
| 215 | $this->buffer->truncate(); |
| 216 | $this->block_count = 0; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Flushes buffer to AvroIO object container and closes it. |