@@ -883,6 +883,7 @@ php_stream_brotli_opener(
883
883
{
884
884
php_brotli_stream_data * self ;
885
885
int level = BROTLI_DEFAULT_QUALITY ;
886
+ zend_string * dict = NULL ;
886
887
int compress ;
887
888
888
889
if (strncasecmp (STREAM_NAME , path , sizeof (STREAM_NAME )- 1 ) == 0 ) {
@@ -912,7 +913,13 @@ php_stream_brotli_opener(
912
913
context , "brotli" , "level" ))) {
913
914
level = zval_get_long (tmpzval );
914
915
}
916
+
917
+ if (NULL != (tmpzval = php_stream_context_get_option (
918
+ context , "brotli" , "dict" ))) {
919
+ dict = zval_get_string (tmpzval );
920
+ }
915
921
}
922
+
916
923
if (level > BROTLI_MAX_QUALITY ) {
917
924
php_error_docref (NULL , E_WARNING ,
918
925
"brotli: set compression level (%d)"
@@ -934,32 +941,52 @@ php_stream_brotli_opener(
934
941
options | REPORT_ERRORS , NULL );
935
942
if (!self -> stream ) {
936
943
efree (self );
944
+ if (dict ) {
945
+ zend_string_release (dict );
946
+ }
937
947
return NULL ;
938
948
}
939
949
940
950
php_brotli_context_init (& self -> ctx );
941
951
942
952
/* File */
943
953
if (compress ) {
944
- if (php_brotli_context_create_encoder (& self -> ctx ,
945
- level , 0 , 0 ) != SUCCESS ) {
954
+ if (php_brotli_context_create_encoder_ex (& self -> ctx , level , 0 , 0 ,
955
+ dict , 0 ) != SUCCESS ) {
946
956
php_error_docref (NULL , E_WARNING ,
947
957
"brotli: failed to prepare compression" );
958
+ php_brotli_context_close (& self -> ctx );
948
959
php_stream_close (self -> stream );
949
960
efree (self );
961
+ if (dict ) {
962
+ zend_string_release (dict );
963
+ }
950
964
return NULL ;
951
965
}
952
966
967
+ if (dict ) {
968
+ zend_string_release (dict );
969
+ }
970
+
953
971
return php_stream_alloc (& php_stream_brotli_write_ops , self , NULL , mode );
954
972
} else {
955
- if (php_brotli_context_create_decoder (& self -> ctx ) != SUCCESS ) {
973
+ if (php_brotli_context_create_decoder_ex (& self -> ctx ,
974
+ dict , 0 ) != SUCCESS ) {
956
975
php_error_docref (NULL , E_WARNING ,
957
976
"brotli: failed to prepare decompression" );
977
+ php_brotli_context_close (& self -> ctx );
958
978
php_stream_close (self -> stream );
959
979
efree (self );
980
+ if (dict ) {
981
+ zend_string_release (dict );
982
+ }
960
983
return NULL ;
961
984
}
962
985
986
+ if (dict ) {
987
+ zend_string_release (dict );
988
+ }
989
+
963
990
self -> result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT ;
964
991
965
992
return php_stream_alloc (& php_stream_brotli_read_ops , self , NULL , mode );
0 commit comments