From 9dfbfb24350b1d6b2f48ce66df8873c072f34a06 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 8 Mar 2018 14:38:58 +0100 Subject: Implement compression level handling for zstd This is a simplified variant of the code for xz, adapted to support multiple digit integers. --- apt-pkg/contrib/fileutl.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'apt-pkg') 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 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() { -- cgit v1.2.3