Added Bzip2 codec.
diff --git a/lang/php/lib/avro/data_file.php b/lang/php/lib/avro/data_file.php
index 3acd5f7..f071895 100644
--- a/lang/php/lib/avro/data_file.php
+++ b/lang/php/lib/avro/data_file.php
@@ -76,7 +76,9 @@
const SNAPPY_CODEC = 'snappy';
const ZSTANDARD_CODEC = 'zstandard';
-
+
+ const BZIP2_CODEC = 'bzip2';
+
/**
* @var array array of valid codec names
*/
@@ -331,6 +333,13 @@
} else {
$decoder = new AvroIOBinaryDecoder(new AvroStringIO(snappy_uncompress($datum)));
}
+ } elseif ($this->codec === AvroDataIO::BZIP2_CODEC) {
+ if (!extension_loaded('bz2')) {
+ throw new AvroException('Please install ext-bz2 to use bzip2 compression.');
+ }
+ $compressed = $decoder->read($length);
+ $datum = bzdecompress($compressed);
+ $decoder = new AvroIOBinaryDecoder(new AvroStringIO($datum));
}
}
$data[] = $this->datum_reader->read($decoder);
@@ -548,6 +557,11 @@
$crc32 = crc32($to_write);
$compressed = snappy_compress($to_write);
$to_write = pack('a*N', $compressed, $crc32);
+ } elseif ($this->codec === AvroDataIO::BZIP2_CODEC) {
+ if (!extension_loaded('bz2')) {
+ throw new AvroException('Please install ext-bz2 to use bzip2 compression.');
+ }
+ $to_write = bzcompress($to_write);
}
$this->encoder->write_long(strlen($to_write));
diff --git a/lang/php/test/InterOpTest.php b/lang/php/test/InterOpTest.php
index 0fc2d2c..fe44029 100644
--- a/lang/php/test/InterOpTest.php
+++ b/lang/php/test/InterOpTest.php
@@ -39,7 +39,7 @@
die("Could not open data dir '$data_dir'\n");
while ($file = readdir($dh))
- if (0 < preg_match('/^[a-z]+(_deflate|_snappy|_zstandard)?\.avro$/', $file))
+ if (0 < preg_match('/^[a-z]+(_deflate|_snappy|_zstandard|_bzip2)?\.avro$/', $file))
$data_files []= implode(DIRECTORY_SEPARATOR, array($data_dir, $file));
closedir($dh);
diff --git a/share/docker/Dockerfile b/share/docker/Dockerfile
index 3d142f5..c8de67a 100644
--- a/share/docker/Dockerfile
+++ b/share/docker/Dockerfile
@@ -87,7 +87,9 @@
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
&& apt-get -qqy update \
&& apt-get -qqy install --no-install-recommends libzstd-dev \
+ libbz2-dev \
php${PHP7_VERSION} \
+ php${PHP7_VERSION}-bz2 \
php${PHP7_VERSION}-gmp \
php${PHP7_VERSION}-xml \
php${PHP7_VERSION}-mbstring \