From: Sara Golemon Date: Tue, 24 Oct 2017 02:10:56 +0000 (-0400) Subject: Add support for zlib/level context option X-Git-Tag: php-7.3.0alpha1~1191 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f804a2128d7109ad6561aff9894ab1ee9244611;p=php Add support for zlib/level context option --- diff --git a/NEWS b/NEWS index 576e66544f..58b2e59ee0 100644 --- a/NEWS +++ b/NEWS @@ -110,4 +110,7 @@ PHP NEWS . Fixed unzserialize(), to disable creation of unsupported data structures through manually crafted strings. (Dmitry) +- Zlib: + . Added zlib/level context option for compress.zlib wrapper. (Sara) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/zlib/tests/zlib_wrapper_level.phpt b/ext/zlib/tests/zlib_wrapper_level.phpt new file mode 100644 index 0000000000..135ef9c72a --- /dev/null +++ b/ext/zlib/tests/zlib_wrapper_level.phpt @@ -0,0 +1,36 @@ +--TEST-- +compress.zlib:// wrapper with compression level +--SKIPIF-- + ['level' => $level] ]); + $fp = fopen("compress.zlib://$filename", 'w', false, $ctx); + for ($i = 0; $i < 10; ++$i) { + fwrite($fp, $thisfile); + } + fclose($fp); + $size = filesize($filename); + unlink($filename); + return $size; +} + +$size1 = write_at_level(1); +$size9 = write_at_level(9); + +var_dump(10 * strlen($thisfile)); +var_dump($size1); +var_dump($size9); +var_dump($size9 < $size1); +--EXPECTF-- +int(%d) +int(%d) +int(%d) +bool(true) diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index 01539aec5c..60147999fe 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -141,6 +141,11 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, con self->gz_file = gzdopen(dup(fd), mode); if (self->gz_file) { + zval *zlevel = context ? php_stream_context_get_option(context, "zlib", "level") : NULL; + if (zlevel && (Z_OK != gzsetparams(self->gz_file, zval_get_long(zlevel), Z_DEFAULT_STRATEGY))) { + php_error(E_WARNING, "failed setting compression level"); + } + stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) { stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;