@@ -1204,18 +1204,17 @@ static int php_zstd_output_encoding(void)
12041204 return PHP_ZSTD_G (compression_coding );
12051205}
12061206
1207- static void
1208- php_zstd_output_handler_load_dict (php_zstd_context * ctx , int level )
1207+ static zend_string *
1208+ php_zstd_output_handler_load_dict (php_zstd_context * ctx )
12091209{
12101210 php_stream * stream = NULL ;
12111211 zval * zcontext = NULL ;
12121212 php_stream_context * context = NULL ;
1213- zend_string * contents = NULL ;
12141213 zend_long maxlen = (ssize_t ) PHP_STREAM_COPY_ALL ;
12151214 char * dict = PHP_ZSTD_G (output_compression_dict );
12161215
12171216 if (!dict || strlen (dict ) <= 0 ) {
1218- return ;
1217+ return NULL ;
12191218 }
12201219
12211220 context = php_stream_context_from_zval (zcontext , 0 );
@@ -1224,29 +1223,19 @@ php_zstd_output_handler_load_dict(php_zstd_context *ctx, int level)
12241223 NULL , context );
12251224 if (!stream ) {
12261225 ZSTD_WARNING ("could not open dictionary stream: %s" , dict );
1227- return ;
1226+ return NULL ;
12281227 }
12291228
12301229 if (php_stream_is (stream , PHP_STREAM_IS_STDIO )) {
12311230 php_stream_set_option (stream , PHP_STREAM_OPTION_READ_BUFFER ,
12321231 PHP_STREAM_BUFFER_NONE , NULL );
12331232 }
12341233
1235- contents = php_stream_copy_to_mem (stream , maxlen , 0 );
1236-
1237- if (contents ) {
1238- ctx -> cdict = ZSTD_createCDict (ZSTR_VAL (contents ), ZSTR_LEN (contents ),
1239- level );
1240- if (!ctx -> cdict ) {
1241- ZSTD_WARNING ("failed to create compression dictionary: %s" , dict );
1242- }
1243-
1244- zend_string (contents );
1245- } else {
1246- ZSTD_WARNING ("failed to get dictionary stream: %s" , dict );
1247- }
1234+ zend_string * data = php_stream_copy_to_mem (stream , maxlen , 0 );
12481235
12491236 php_stream_close (stream );
1237+
1238+ return data ;
12501239}
12511240
12521241static zend_result php_zstd_output_handler_context_start (php_zstd_context * ctx )
@@ -1262,7 +1251,7 @@ static zend_result php_zstd_output_handler_context_start(php_zstd_context *ctx)
12621251 return FAILURE ;
12631252 }
12641253
1265- php_zstd_output_handler_load_dict (ctx , level );
1254+ php_zstd_output_handler_load_dict (ctx );
12661255
12671256 ZSTD_CCtx_reset (ctx -> cctx , ZSTD_reset_session_only );
12681257 ZSTD_CCtx_refCDict (ctx -> cctx , ctx -> cdict );
0 commit comments