From 32ac26a4e7c9b1b0a575edafc4568be7aee62c8e Mon Sep 17 00:00:00 2001 From: "Sergey G. Brester" Date: Thu, 7 Sep 2023 12:32:44 +0200 Subject: [PATCH 1/4] README.md - brotli (de)compress, new hash algorithms amend to #330, #351 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8df00989..827db712 100644 --- a/README.md +++ b/README.md @@ -114,13 +114,13 @@ Hashers: ### Usage and features of the full installation - compression and decompression for [Brotli], [Lizard], [LZ4], [LZ5] and [Zstandard] within the [7-Zip] container format -- compression and decompression of [Lizard] (`.liz`), [LZ4] (`.lz4`), [LZ5] (`.lz5`) and [Zstandard] (`.zst`) files +- compression and decompression of [Brotli] (`.br`), [Lizard] (`.liz`), [LZ4] (`.lz4`), [LZ5] (`.lz5`) and [Zstandard] (`.zst`) files - handling of ZIP files with [Zstandard] compression - included [lzip] decompression support, patch from: https://download.savannah.gnu.org/releases/lzip/7zip/ - explorer context menu: _"Add to xy.7z"_ will use all parameters of the last "Add to Archive" compression dialog (this includes: method, level, dictionary, blocksize, threads and paramters input box) - squashfs files with LZ4 or Zstandard compression can be handled - several history settings aren't stored by default, look [here](https://sourceforge.net/p/sevenzip/discussion/45797/thread/dc2ac53d/?limit=25) for some info about that, you can restore original 7-Zip behavior via `tools->options->settings` -- these hashes can be calculated: CRC32, CRC64, MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512, XXH32, XXH64, BLAKE2sp, BLAKE3 (lowercase or uppercase) +- these hashes can be calculated: CRC32, CRC64, MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512, SHA3-256, SHA3-384, SHA3-512, XXH32, XXH64, BLAKE2sp, BLAKE3 (lowercase or uppercase) ``` 7z a archiv.7z -m0=zstd -mx0 Zstandard Fastest Mode, without BCJ preprocessor From 2b48366507849052cfdf2b6a5bff429993a5a6b8 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 7 Sep 2023 20:26:17 +0200 Subject: [PATCH 2/4] 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; } From 6411fade3ce7ae5521f8c6e8f84fa836f134b811 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 7 Sep 2023 20:27:38 +0200 Subject: [PATCH 3/4] translate threads to decoder (previously ignored): important for -mmt>=2 to use brotli-mt (the streams are incompatible) --- CPP/7zip/Archive/BrotliHandler.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CPP/7zip/Archive/BrotliHandler.cpp b/CPP/7zip/Archive/BrotliHandler.cpp index 734ac5e8..f513c8cf 100644 --- a/CPP/7zip/Archive/BrotliHandler.cpp +++ b/CPP/7zip/Archive/BrotliHandler.cpp @@ -173,6 +173,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, NCompress::NBROTLI::CDecoder *decoderSpec = new NCompress::NBROTLI::CDecoder; decoderSpec->SetNumberOfThreads(0); /* .br - single threaded processing (without header/mt-frames) */ + if (_props._numThreads_WasForced) { + decoderSpec->SetNumberOfThreads(_props._numThreads); // translate to decoder (important for -mmt>=2 to use brotli-mt) + } CMyComPtr decoder = decoderSpec; decoderSpec->SetInStream(_seqStream); From 09a6777b9623618e6c802ae88d1e5ef2938c544d Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 11 Sep 2023 15:39:02 +0200 Subject: [PATCH 4/4] amend to #351: fixes register of zip archive (after adding of brotli codec, zip type gets missing because exceeded kNumArcsMax in registering structure g_Arcs) --- CPP/7zip/Archive/ArchiveExports.cpp | 2 +- CPP/7zip/UI/Common/LoadCodecs.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CPP/7zip/Archive/ArchiveExports.cpp b/CPP/7zip/Archive/ArchiveExports.cpp index 8a441bc2..a84a3cbb 100644 --- a/CPP/7zip/Archive/ArchiveExports.cpp +++ b/CPP/7zip/Archive/ArchiveExports.cpp @@ -10,7 +10,7 @@ #include "../Common/RegisterArc.h" -static const unsigned kNumArcsMax = 64; +static const unsigned kNumArcsMax = 72; static unsigned g_NumArcs = 0; static unsigned g_DefaultArcIndex = 0; static const CArcInfo *g_Arcs[kNumArcsMax]; diff --git a/CPP/7zip/UI/Common/LoadCodecs.cpp b/CPP/7zip/UI/Common/LoadCodecs.cpp index 39562d2a..4f15407b 100644 --- a/CPP/7zip/UI/Common/LoadCodecs.cpp +++ b/CPP/7zip/UI/Common/LoadCodecs.cpp @@ -122,7 +122,7 @@ static bool ReadPathFromRegistry(HKEY baseKey, LPCWSTR value, FString &path) #endif // EXTERNAL_CODECS -static const unsigned kNumArcsMax = 64; +static const unsigned kNumArcsMax = 72; static unsigned g_NumArcs = 0; static const CArcInfo *g_Arcs[kNumArcsMax];