Menu

Feature request: Option to include full compression settings in 7z archive

Kukris
2020-10-27
2020-10-30
  • Kukris

    Kukris - 2020-10-27

    Greetings,

    It would be useful to have an option to include the full compression settings (GUI as well as command line) in a 7z archive (like a log file or meta data in header).
    I test various settings to achieve a good compression and when I encounter folders and files with a similiar structure and file types I want to use the same settings.

    Though there is a column "Method" in the 7z archive I have problems to figure out what these settings mean or how to translate them to the GUI or command line version.

    Example: Compression settings via GUI

    Archive format: 7z
    Compression level: Ultra
    Compression method: LZMA2
    Dictionary size: 768 MB
    Word size: 256
    Solid Block size: 4 GB
    Optional: Other settings
    

    When I create a 7z archive with these settings and then open the finished archive I can see that not all files have the same settings in the column "Method" though I only specified one setting.

    file.exe, Method: BCJ2 LZMA2:768m LZMA:20:lc0:lp2 LZMA:20:lc0:lp2
    file.bin, Method: LZMA2:768m
    

    Now it would be great to have these settings as clear text as above for the GUI version and as well as a command line (7z a -t7z ....).

     
  • Igor Pavlov

    Igor Pavlov - 2020-10-27

    BCJ2 is default data filter for executable files, that increases the compression ratio.

     
  • Kukris

    Kukris - 2020-10-28

    OK, thanks. That explains the different methods, but the main issue remains to have an option to include the compression settings in a 7z archive.

    Not all compression settings are listed in the column "Method" or I cannot decipher them, like Compression level, Word size, Solid Block size.

     
  • Igor Pavlov

    Igor Pavlov - 2020-10-29

    There are some compatibility reasons why we can't change it.

     
  • Kukris

    Kukris - 2020-10-29

    What a pity, but thanks for the answer

     
  • Shell

    Shell - 2020-10-30

    Kukris, when you yourself create archives, you can put the compression settings into a small text file and add it to the archive. It is especially convenient with the command-line version, e.g.:
    set 7zset=-mx9 -s4g -m0=lzma2:d768m:fb256
    echo %7zset%>settings.log
    7z a %7zset% archive.7z settings.log files

    This example shows the settings from your first post (without other settings). Some of them are default, but I have deliberately shown them.

    Only some settings can be deduced from the archive. Compression method and filters are always available. On the other hand, only lower bounds can be given for solid block size and word size, and the number of cycles (one of the optional parameters) cannot be recovered at all. For LZMA, most parameters are stored explicitly in the stream, so they are shown if their values differ from the default ones. For LZMA2, it is harder to recover them, so 7-Zip shows only dictionary size.

    I'll now show how to decipher the Method column for a given file. The name of method/filter is shown first, its parameters follow, separated with colons. The syntax is exactly the same as for command-line 7-Zip (see Help for the -m switch for details). You only need to enumerate the methods and to bind them between each other. In the case of file.exe, you have 4 methods. If you start enumerating from 0, you get the following command line:
    -m0=BCJ2 -m1=LZMA2:768m -m2=LZMA:20:lc0:lp2 -m3=LZMA:20:lc0:lp2
    If a parameter is not shown, it either has default value (e.g. pb2 for methods #2 and #3) or it cannot be recovered easily. Now you should find out which methods should be bound to other ones. You can find that LZMA and LZMA2 produce a single stream, but BCJ2 produces 4 streams. This means that up to 4 methods that follow BCJ2 must be bound to it. Thus, you add the following switches:
    -mb0s0:1 -mb0s1:2 -mb0s2:3
    This means that method #0's (BCJ2) stream 0 (unlike methods, streams are always numbered from zero) is compressed with method #1 (LZMA2); stream 1, with #2, and stream 2, with #3. Stream 3 is not bound, so it goes uncompressed.

    In order to combine the settings for different files, you need to understand which ones are default. In the above example, BCJ2 codec and LZMA methods for its streams are automatically applied for PE executables for compression level Ultra, so instead of
    -mx9 -m0=BCJ2 -m1=LZMA2:768m -m2=LZMA:20:lc0:lp2 -m3=LZMA:20:lc0:lp2 -mb0s0:1 -mb0s1:2 -mb0s2:3
    you can write simply
    -mx9 -m0=LZMA2:d768m
    And this is exactly what is applied to file.bin.

     

Log in to post a comment.