@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
5050
5151struct private_data {
5252 int compression_level ;
53+ int threads ;
5354#if HAVE_ZSTD_H && HAVE_LIBZSTD
5455 ZSTD_CStream * cstream ;
5556 int64_t total_in ;
@@ -107,6 +108,7 @@ archive_write_add_filter_zstd(struct archive *_a)
107108 f -> code = ARCHIVE_FILTER_ZSTD ;
108109 f -> name = "zstd" ;
109110 data -> compression_level = CLEVEL_DEFAULT ;
111+ data -> threads = 0 ;
110112#if HAVE_ZSTD_H && HAVE_LIBZSTD
111113 data -> cstream = ZSTD_createCStream ();
112114 if (data -> cstream == NULL ) {
@@ -204,6 +206,20 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
204206 }
205207 data -> compression_level = level ;
206208 return (ARCHIVE_OK );
209+ } else if (strcmp (key , "threads" ) == 0 ) {
210+ int threads = atoi (value );
211+ if (string_is_numeric (value ) != ARCHIVE_OK ) {
212+ return (ARCHIVE_WARN );
213+ }
214+
215+ int minimum = 0 ;
216+
217+ if (threads < minimum ) {
218+ return (ARCHIVE_WARN );
219+ }
220+
221+ data -> threads = threads ;
222+ return (ARCHIVE_OK );
207223 }
208224
209225 /* Note: The "warn" return is just to inform the options
@@ -252,6 +268,8 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
252268 return (ARCHIVE_FATAL );
253269 }
254270
271+ ZSTD_CCtx_setParameter (data -> cstream , ZSTD_c_nbWorkers , data -> threads );
272+
255273 return (ARCHIVE_OK );
256274}
257275
@@ -366,6 +384,14 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
366384 archive_strcat (& as , " --ultra" );
367385 }
368386
387+ if (data -> threads != 0 ) {
388+ struct archive_string as2 ;
389+ archive_string_init (& as2 );
390+ archive_string_sprintf (& as , " --threads=%d" , data -> threads );
391+ archive_string_concat (& as , & as2 );
392+ archive_string_free (& as2 );
393+ }
394+
369395 f -> write = archive_compressor_zstd_write ;
370396 r = __archive_write_program_open (f , data -> pdata , as .s );
371397 archive_string_free (& as );
0 commit comments