Merge pull request #1567 from russelltg/russell_zstd_threads
zstd filter writer: add threads option
This commit is contained in:
2 files changed
+30
No files matched your search
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
struct private_data {
|
||||
int compression_level;
|
||||
int threads;
|
||||
#if HAVE_ZSTD_H && HAVE_LIBZSTD
|
||||
ZSTD_CStream *cstream;
|
||||
int64_t total_in;
|
||||
@@ -107,6 +108,7 @@ archive_write_add_filter_zstd(struct archive *_a)
|
||||
f->code = ARCHIVE_FILTER_ZSTD;
|
||||
f->name = "zstd";
|
||||
data->compression_level = CLEVEL_DEFAULT;
|
||||
data->threads = 0;
|
||||
#if HAVE_ZSTD_H && HAVE_LIBZSTD
|
||||
data->cstream = ZSTD_createCStream();
|
||||
if (data->cstream == NULL) {
|
||||
@@ -204,6 +206,20 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
|
||||
}
|
||||
data->compression_level = level;
|
||||
return (ARCHIVE_OK);
|
||||
} else if (strcmp(key, "threads") == 0) {
|
||||
int threads = atoi(value);
|
||||
if (string_is_numeric(value) != ARCHIVE_OK) {
|
||||
return (ARCHIVE_WARN);
|
||||
}
|
||||
|
||||
int minimum = 0;
|
||||
|
||||
if (threads < minimum) {
|
||||
return (ARCHIVE_WARN);
|
||||
}
|
||||
|
||||
data->threads = threads;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
/* Note: The "warn" return is just to inform the options
|
||||
@@ -252,6 +268,8 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
ZSTD_CCtx_setParameter(data->cstream, ZSTD_c_nbWorkers, data->threads);
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -366,6 +384,14 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
|
||||
archive_strcat(&as, " --ultra");
|
||||
}
|
||||
|
||||
if (data->threads != 0) {
|
||||
struct archive_string as2;
|
||||
archive_string_init(&as2);
|
||||
archive_string_sprintf(&as2, " --threads=%d", data->threads);
|
||||
archive_string_concat(&as, &as2);
|
||||
archive_string_free(&as2);
|
||||
}
|
||||
|
||||
f->write = archive_compressor_zstd_write;
|
||||
r = __archive_write_program_open(f, data->pdata, as.s);
|
||||
archive_string_free(&as);
|
||||
|
||||
@@ -129,6 +129,10 @@ DEFINE_TEST(test_write_filter_zstd)
|
||||
archive_write_set_filter_option(a, NULL, "compression-level", "-1")); */
|
||||
assertEqualIntA(a, ARCHIVE_OK,
|
||||
archive_write_set_filter_option(a, NULL, "compression-level", "7"));
|
||||
assertEqualIntA(a, ARCHIVE_FAILED,
|
||||
archive_write_set_filter_option(a, NULL, "threads", "-1")); /* negative */
|
||||
assertEqualIntA(a, ARCHIVE_OK,
|
||||
archive_write_set_filter_option(a, NULL, "threads", "4"));
|
||||
assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
|
||||
for (i = 0; i < 100; i++) {
|
||||
sprintf(path, "file%03d", i);
|
||||
|
||||
Reference in new issue
Block a user