diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2018-03-08 14:38:58 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2018-04-13 23:15:06 +0200 |
commit | 9dfbfb24350b1d6b2f48ce66df8873c072f34a06 (patch) | |
tree | cb870bde39fd194a3da97176bdc0db76db87fecb /apt-pkg | |
parent | b91aff572bcbdfa9fbcc9be09778828718a62e34 (diff) | |
download | apt-9dfbfb24350b1d6b2f48ce66df8873c072f34a06.tar.gz |
Implement compression level handling for zstd
This is a simplified variant of the code for xz, adapted to support
multiple digit integers.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index fc14422d6..5acf40221 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1740,7 +1740,7 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly) { cctx = ZSTD_createCStream(); - res = ZSTD_initCStream(cctx, 19); + res = ZSTD_initCStream(cctx, findLevel(compressor.CompressArgs)); zstd_buffer.reset(APT_BUFFER_SIZE); } else @@ -1898,6 +1898,23 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate return ZSTD_isError(res) == false; } + static uint32_t findLevel(std::vector<std::string> const &Args) + { + for (auto a = Args.rbegin(); a != Args.rend(); ++a) + { + if (a->size() >= 2 && (*a)[0] == '-' && (*a)[1] != '-') + { + auto const level = a->substr(1); + auto const notANumber = level.find_first_not_of("0123456789"); + if (notANumber != std::string::npos) + continue; + + return (uint32_t)stoi(level); + } + } + return 19; + } + explicit ZstdFileFdPrivate(FileFd *const filefd) : FileFdPrivate(filefd), dctx(nullptr), cctx(nullptr) {} virtual ~ZstdFileFdPrivate() { |