From 2b48366507849052cfdf2b6a5bff429993a5a6b8 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 7 Sep 2023 20:26:17 +0200 Subject: [PATCH] if single-threaded brotli, retain artificial number set in BrotliHandler (0) - always prefer it for .br format, otherwise `-mmt1` causes that it'd use brotli-mt and the stream is incompatible; `-mmt=n` with `n >= 2` forces multi-threaded compression/decompression (therefore incompatible with standard brotli) --- CPP/7zip/Compress/BrotliDecoder.cpp | 4 ++++ CPP/7zip/Compress/BrotliEncoder.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CPP/7zip/Compress/BrotliDecoder.cpp b/CPP/7zip/Compress/BrotliDecoder.cpp index 5027c089..910ec4f7 100644 --- a/CPP/7zip/Compress/BrotliDecoder.cpp +++ b/CPP/7zip/Compress/BrotliDecoder.cpp @@ -100,6 +100,10 @@ STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 numThreads) const UInt32 kNumThreadsMax = BROTLIMT_THREAD_MAX; if (numThreads < 0) numThreads = 0; if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax; + // if single-threaded, retain artificial number set in BrotliHandler (always prefer .br format): + if (_numThreads == 0 && numThreads == 1) { + numThreads = 0; + } _numThreads = numThreads; return S_OK; } diff --git a/CPP/7zip/Compress/BrotliEncoder.cpp b/CPP/7zip/Compress/BrotliEncoder.cpp index b1dcb613..b44fc582 100644 --- a/CPP/7zip/Compress/BrotliEncoder.cpp +++ b/CPP/7zip/Compress/BrotliEncoder.cpp @@ -156,6 +156,10 @@ STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads) const UInt32 kNumThreadsMax = BROTLIMT_THREAD_MAX; if (numThreads < 0) numThreads = 0; if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax; + // if single-threaded, retain artificial number set in BrotliHandler (always prefer .br format): + if (_numThreads == 0 && numThreads == 1) { + numThreads = 0; + } _numThreads = numThreads; return S_OK; }