# -m (Set compression Method) switch

Specifies compression method.

#### Syntax

    -m<method_parameters>

Format of this switch is depended from archive type.

#### Zip

Parameter | Default | Description
--- | --- | ---
x=[0 | 5 | 9 ] | 5 | Sets level of compression.
m={MethodID} | Deflate | Sets a method: Copy, Deflate, Deflate64, BZip2.
fb={NumFastBytes} | 32 | Sets number of Fast Bytes for Deflate encoder.
pass={NumPasses} | 1 | Sets number of Passes for Deflate encoder.

x=[0 | 5 | 9 ]

  Sets level of compression

  Level | Description
  --- | ---
  0 | No compression.
  5 | Default compression method.
  9 | Maximum compression method. It can require additional amount of RAM and compressing process can be slower.

fb={NumFastBytes}

  Sets number of fast bytes for Deflate/Deflate64 encoder. It can be in range from 3 to 258 (257 for Deflate64). Default value is 32 for normal mode and 64 for maximum mode. Usually big number gives a little bit better compression ratio and slower compression process. Big number of fast bytes parameter can significantly increase compression ratio in case when files contain long identical sequences of bytes.

pass={NumPasses}

  Sets number of passes for Deflate encoder. It can be in range from 1 to 10. Default value is 1 for normal mode and 3 for maximum mode. Usually big number gives a little bit better compression ratio and slower compression process. If you use more than one pass, deflate encoder will use additional (128 * NumFastBytes) KB.

#### GZip

GZip uses the same parameters as Zip, but GZip compresses only with Defalte method.

#### BZip2

Parameter | Default | Description
--- | --- | ---
x=[5 | 7 | 9 ] | 5 | Sets level of compression.
pass={NumPasses} | 1 | Sets number of Passes for Bzip2 encoder.

x=[5 | 7 | 9 ]

  Sets level of compression

  Level | Description
  --- | ---
  5 | Default compression method (1 pass).
  7 | Maximum compression method (2 passes).
  9 | Ultra compression method (7 passes).

pass={NumPasses}

  Sets number of passes. It can be in range from 1 to 10. Default value is 1 for normal mode, 2 for maximum mode and 7 for ultra mode. Bigger number can give a little bit better compression ratio and slower compression process.

#### 7z

Parameter | Default | Description
--- | --- | ---
x=[0 | 1 | 5 | 7 | 9 ] | 5 | Sets level of compression.
s=[off | on | [e] [{N}f] [{N}b | {N}k | {N}m | {N}g] | on | Sets solid mode.
f=[off | on] | on | Enables or disables compression filters for executable files.
hc=[off | on] | on | Enables or disables archive header compressing.
hcf=[off | on] | on | Enables or disables full archive header compressing.
he=[off | on] | off | Enables or disables archive header encryption.
b{C1}[s{S1}]:{C2}[s{S2}] |  | Sets binding beetwen coders.
{N}={MethodID}[:param1][:param2][..] | LZMA | Sets a method: LZMA, PPMd, BZip2, Deflate, BCJ, BCJ2, Copy.
mt=[off | on] | off | Sets multithreading mode.

x=[0 | 1 | 5 | 7 | 9 ]

  Sets level of compression

  Level | Description
  --- | ---
  0 | No compression.
  1 | Fast compressing: fast LZMA mode, 32KB dictionary, HC3 Match finder, BCJ filter.
  5 | Normal compressing: normal LZMA mode, 2 MB dictionary, BT4 Match finder, NumFastBytes is 32, BCJ filter.
  7 | Maximum compressing: maximum LZMA mode, 8 MB dictionary size, BT4 Match finder, NumFastBytes is 64, BCJ filter.
  9 | Ultra compressing: maximum LZMA mode, 32 MB dictionary size, BT4b Match finder, , NumFastBytes is 64, BCJ2 filter.

s=[off | on | [e] [{N}f] [{N}b | {N}k | {N}m | {N}g)]

  Enables or disables solid mode. The default mode is s=on. In solid mode files are grouped together. Usually compressing in solid mode improves compression ratio.

  e | Use separate solid block for each new file extension
  {N}f | Set limit for number of files in one solid block
  {N}b | {N}k | {N}m | {N}g | Set limit for total size of solid block in bytes

  By default there is limitation for solid block size:

  Compression Level | Solid block size
  --- | ---
  Store | 0 B
  Fast | 16 MB
  Normal | 256 MB
  Maximum | 1 GB
  Ultra | 4 GB

  Limitation for solid block size usually decreases compression ratio but gives the following advantages:

  - Decreases losses in case of future archive's damaging.
  - Decreases extracting time of the group of files (it can be one file), if this group doesn't contain all files of archive.

  Current version of 7-Zip doesn't support updating for solid archives, if it requires repacking solid blocks.

  Example:

              -s=100f10m

  set solid mode with 100 files & 10 MB limits per one solid block.

f=[off | on]

  Enables or disables compression filters for executable files: dll, exe, ocx, sfx, sys. It uses BCJ2 filter in Ultra mode and BCJ filter in other modes. The default mode is f=on.

hc=[off | on]

  Enables or disables archive header compressing. The default mode is hc=on. If archive header compressing is enabled, some parts of archive header will be compressed with LZMA method.

hcf=[off | on]

  Enables or disables full archive header compressing. The default mode is hcf=on. Archives created with hcf=on can be extracted by 7-Zip 2.30 beta 25 and more.

he=[off | on]

  Enables or disables archive header encryption. The default mode is he=off.

{N}

  Sets order of methods. It is used also to associate parameters with methods. Numbers must begin from 0. Method that have minor number will be used before others.

b{C1}[s{S1}]:{C2}[s{S2}]

  Binds output stream S1 in coder C1 with input stream S2 in coder C2. If stream number is not specified, stream with number 0 will be used.

  Usally coder has one input stream and one output stream. In 7z some coders can have multiple input and output streams.

  For example, BCJ2 encoder has one input stream and four output streams.

mt=[off | on]

  Sets multithread mode. If you have multiprocessor system or Pentium 4 with hyperthreading, you can get compressing speed increasing with switching multithreading option on. This option affects only LZMA compressing.

{N}={MethodID}[:param1][:param2] ... [:paramN]

  Sets compression method. You can use any number of methods. The default method is LZMA.

  Parameters must be in one of the following forms:

  - {ParamName}={ParamValue}.
  - {ParamName}{ParamValue}, if {ParamValue} is number and {ParamName} doesn't contain numbers.

  Supported methods:

  MethodID | Description
  --- | ---
  LZMA | Algorithm based on LZ algorithm
  PPMd | Dmitry Shkarin's PPMdH with small changes
  BZip2 | BWT algorithm
  Deflate | LZ+Huffman
  Copy | No compression

  Supported filters:

  MethodID | Description
  --- | ---
  BCJ | converter for x86 executables
  BCJ2 | converter for x86 executables (version 2)
  BC_ARM | converter for ARM (little endian) executables
  BC_ARMThumb | converter for ARM Thumb (little endian) executables
  BC_IA64 | converter for IA-64 executables
  BC_PPC_B | converter for PowerPC (big endian) executables
  BC_SPARC | converter for SPARC executables

  Filters allow to increase compression ratio for some types of files. Filters must be used with one of the compression method (for example, BCJ + LZMA).

#### LZMA

LZMA is an algorithm based on Lempel-Ziv algorithm. It provides very fast decompressing (about 10-20 times faster than compressing). Memory requirements for compressing and decompressing also are different (see d={Size}[b|k|m] switch for details).

Parameter | Default | Description
--- | --- | ---
a=[0|1|2] | 1 | Sets compressing mode
d={Size}[b|k|m] | 20 | Sets Dictionary size
mf={MF_ID} | bt4 | Sets Match Finder
fb={N} | 32 | Sets number of Fast Bytes
lc={N} | 3 | Sets number of Literal Context bits - [0, 8]
lp={N} | 0 | Sets number of Literal Pos bits - [0, 4]
pb={N} | 2 | Set number of Pos Bits - [0, 4]

a=[0|1|2]

  Sets compressing mode: 0 = fast, 1 = normal, 2 = max ratio. Default value is 1.

d={Size}[b|k|m]

  Sets Dictionary size for LZMA. You must specify size in bytes, kilobytes, or megabytes. The maximum value for dictionary size is 256MB = 2^28 bytes. Default value for LZMA is 21 (2 MB) in normal mode, 23 (8 MB) in maiximum mode (-mx=7) and 25 (32 MB) in ultra mode (-mx=9). If you do not specify any symbol from set [b|k|m], dictionary size will be calculated as DictionarySize = 2^Size bytes. For decompressing file compressed by LZMA method with dictionary size N you need about N bytes of memory (RAM) available.

mf={MF_ID}

  Sets Match Finder for LZMA. Default method is bt4. Methods from bt* group require less memory than methods from pat* group. Usually bt4 works faster than any pat*, but for some types of files pat* can work faster. Algorithms from hc* group doesn't provide good compression ratio, but they often works pretty fast in combination with fast mode (a=0). Memory requirements depend from dictionary size (parameter "d" in table below).

  MF_ID | Memory | Description
  --- | --- | ---
  bt2 | d*9.5 + 1MB | Binary Tree with 2 bytes hashing.
  bt3 | d*9.5 + 65MB | Binary Tree with 2-3(full) bytes hashing.
  bt4 | d*9.5 + 6MB | Binary Tree with 2-3-4 bytes hashing.
  bt4b | d*9.5 + 34MB | Binary Tree with 2-3-4(big) bytes hashing.
  pat2r | d*26 + 1MB | Patricia Tree with 2-bits nodes, removing.
  pat2 | d*38 + 1MB | Patricia Tree with 2-bits nodes.
  pat2h | d*38 + 77MB | Patricia Tree with 2-bits nodes, 2-3 bytes hashing.
  pat3h | d*62 + 85MB | Patricia Tree with 3-bits nodes, 2-3 bytes hashing.
  pat4h | d*110 + 101MB | Patricia Tree with 4-bits nodes, 2-3 bytes hashing.
  hc3 | d*5.5 + 1MB | Hash Chain with 2-3 bytes hashing.
  hc4 | d*5.5 + 6MB | Hash Chain with 2-3-4 bytes hashing.

  Note: Operation system also needs some amount of physical memory for system's purposes. So keep at least 32MB of physical memory unused.

fb={N}

  Sets number of fast bytes for LZMA. It can be in range from 5 to 273. Default value is 32 for normal mode and 64 for maximum mode. Usually big number gives a little bit better compression ratio and slower compression process.

lc={N}

  Sets number of literal context bits (high bits of previous literal). It can be in range from 0 to 8. Default value is 3. Sometimes lc=4 gives gain for big files.

lp={N}

  Sets number of literal pos bits (low bits of current position for literals). It can be in range from 0 to 4. Default value is 0. lp switch is intended for periodical data when period is equal 2^value (where lp=value). For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's better to set lc=0, if you change lp switch.

pb={N}

  Sets number of pos bits (low bits of current position). It can be in range from 0 to 4. Default value is 2. pb switch is intended for periodical data when period is equal 2^value (where lp=value).

#### PPMd

PPMd is a PPM-based algorithm. This algorithm is mostly based on Dmitry Shkarin's PPMdH sources. PPMd provides very good compression ratio for plain text files. There is no difference between compressing speed and decompressing speed. Memory requirements for compressing and decompressing also are the same.

Parameter | Default | Description
--- | --- | ---
mem={Size}[b|k|m] | 24 | Sets size of used memory for PPMd.
o={Size} | 6 | Sets model order for PPMd.

mem={Size}[b|k|m]

  Sets size of used memory for PPMd. You must specify size in bytes, kilobytes, or megabytes. The maximum value is 2GB = 2^31 bytes. Default value is 24 (16MB). If you do not specify any symbol from set [b|k|m], memory size will be calculated as (2^Size) bytes. PPMd uses the same amount of memory for compressing and decompressing.

o={Size}

  Sets model order for PPMd. Size must be in range [2,32]. Default value is 6.

#### BCJ2

BCJ2 is Branch converter for 32-bit x86 executables (version 2). It converts some branch instructions for increasing further compression.

BCJ2 encoder has one input stream and four output streams:

- s0: main stream. It requires further compression.
- s1: stream for converted CALL values. It requires further compression.
- s2: stream for converted JUMP values. It requires further compression.
- s3: service stream. It is already compressed.

If LZMA is used, size of dictionary for streams s1 and s2 can be much smaller (512 KB is enough for most cases) than dictionary size for stream s0.

#### Examples

    7z a -tzip archive.zip *.jpg -mx0

adds *.jpg files to archive.zip archive without compression.

    7z a -t7z archive.7z *.exe *.dll -m0=BCJ -m1=LZMA:d=21 -ms -mmt

adds *.exe and *.dll files to solid archive archive.7z using LZMA method with 2 MB dictionary and BCJ converter. Compressing will use multithreading optimization.

    7z a -t7z archive.7z *.exe *.dll -m0=BCJ2 -m1=LZMA:d23 -m2=LZMA:d19 -m3=LZMA:d19
         -mb0:1 -mb0s1:2 -mb0s2:3

adds *.exe and *.dll files to archive archive.7z using BCJ2 converter, LZMA with 8 MB dictionary for main output stream (s0), and LZMA with 512 KB dictionary for s1 and s2 output streams of BCJ2.

    7z a -t7z archive.7z *.txt -m0=PPMd

adds *.txt files to archive archive.7z using PPMd method.

#### Commands that can be used with this switch

a (Add), d (Delete), u (Update),

#### See also

Switches: -t (set Type of archive),