Compress or decompress .xz and .lzma files
xz [option]... [file]...
This utility: | Is equivalent to: |
---|---|
unxz | xz --decompress |
xzcat | xz --decompress --stdout |
lzma | xz --format=lzma |
unlzma | xz --format=lzma --decompress |
lzcat | xz --format=lzma --decompress --stdout |
When you're writing scripts that need to decompress files, you should use the name xz with appropriate arguments (xz -d or xz -dc) instead of the names unxz and xzcat.
QNX Neutrino
Integer suffixes and special values
In most places where an integer argument is expected, an optional suffix is supported to easily indicate large integers. There must be no space between the integer and the suffix.
You can use the special value max to indicate the maximum integer value supported by the option.
Operation mode
If multiple operation mode options are given, the last one takes effect.
The default listing shows basic information about files, one file per line. To get more detailed information, use also the --verbose option. For even more information, use --verbose twice, but note that this may be slow, because getting all the extra information requires many seeks. The width of verbose output exceeds 80 characters, so piping the output to (for example) less -S may be convenient if the terminal isn't wide enough.
The exact output may vary between xz versions and different locales. For machine-readable output, --robot --list should be used.
Operation modifiers
When decompressing, recognize files with the suffix .suf in addition to files with the .xz, .txz, .lzma, or .tlz suffix. If the source file has the suffix .suf, the suffix is removed to get the target filename.
When compressing or decompressing raw streams (--format=raw), the suffix must always be specified unless writing to standard output, because there's no default suffix for raw streams.
Basic file format and compression options
Supported check types:
Integrity of the .xz headers is always verified with CRC32. It isn't possible to change or disable it.
The differences between the presets are more significant than with gzip and bzip2. The selected compression settings determine the memory requirements of the decompressor, thus using a too-high preset level might make it painful to decompress the file on an old system with little RAM. Specifically, it's not a good idea to blindly use -9 for everything as it often is with gzip and bzip2.
On the same hardware, the decompression speed is approximately a constant number of bytes of compressed data per second. In other words, the better the compression, the faster the decompression will usually be. This also means that the amount of uncompressed output produced per second can vary a lot.
The following table summarizes the features of the presets:
Preset | DictSize | CompCPU | CompMem | DecMem |
---|---|---|---|---|
-0 | 256 KiB | 0 | 3 MiB | 1 MiB |
-1 | 1 MiB | 1 | 9 MiB | 2 MiB |
-2 | 2 MiB | 2 | 17 MiB | 3 MiB |
-3 | 4 MiB | 3 | 32 MiB | 5 MiB |
-4 | 4 MiB | 4 | 48 MiB | 5 MiB |
-5 | 8 MiB | 5 | 94 MiB | 9 MiB |
-6 | 8 MiB | 6 | 94 MiB | 9 MiB |
-7 | 16 MiB | 6 | 186 MiB | 17 MiB |
-8 | 32 MiB | 6 | 370 MiB | 33 MiB |
-9 | 64 MiB | 6 | 674 MiB | 65 MiB |
Column descriptions:
Since there are two presets with dictionary sizes 4 MiB and 8 MiB, the presets -3e and -5e use slightly faster settings (lower CompCPU) than -4e and -6e, respectively. That way no two presets are identical.
Preset | DictSize | CompCPU | CompMem | DecMem |
---|---|---|---|---|
-0e | 256 KiB | 8 | 4 MiB | 1 MiB |
-1e | 1 MiB | 8 | 13 MiB | 2 MiB |
-2e | 2 MiB | 8 | 25 MiB | 3 MiB |
-3e | 4 MiB | 7 | 48 MiB | 5 MiB |
-4e | 4 MiB | 8 | 48 MiB | 5 MiB |
-5e | 8 MiB | 7 | 94 MiB | 9 MiB |
-6e | 8 MiB | 8 | 94 MiB | 9 MiB |
-7e | 16 MiB | 8 | 186 MiB | 17 MiB |
-8e | 32 MiB | 8 | 370 MiB | 33 MiB |
-9e | 64 MiB | 8 | 674 MiB | 65 MiB |
For example, there are a total of four presets that use 8 MiB dictionary, whose order from the fastest to the slowest is -5, -6, -5e, and -6e.
If the compression settings exceed the limit, xz will adjust the settings downwards so that the limit is no longer exceeded and display a notice that automatic adjustment was done. Such adjustments aren't made when compressing with --format=raw or if --no-adjust has been specified. In those cases, an error is displayed and xz will exit with exit status 1.
You can specify the limit in multiple ways:
See also the Memory usage section.
Multithreaded compression and decompression aren't implemented yet, so this option has no effect for now.
As of writing (2010-09-27), it hasn't been decided if threads will be used by default on multicore systems once support for threading has been implemented. Comments are welcome. The complicating factor is that using many threads will increase the memory usage dramatically. Note that if multithreading will be the default, it will probably be done so that single-threaded and multithreaded modes produce the same output, so compression ratio won't be significantly affected if threading will be enabled by default.
Custom compressor filter chains
A custom filter chain allows specifying the compression settings in detail instead of relying on the settings associated to the preset levels. When a custom filter chain is specified, the compression preset level options (-0 ... -9 and --extreme) are silently ignored.
A filter chain is comparable to piping on the command line. When you're compressing, the uncompressed input goes to the first filter, whose output goes to the next filter (if any). The output of the last filter gets written to the compressed file. The maximum number of filters in the chain is four, but typically a filter chain has only one or two filters.
Many filters have limitations on where they can be in the filter chain: some filters can work only as the last filter in the chain, some only as a non-last filter, and some work in any position in the chain. Depending on the filter, this limitation is either inherent to the filter design or exists to prevent security issues.
A custom filter chain is specified by using one or more filter options in the order they are wanted in the filter chain. That is, the order of filter options is significant! When you're decoding raw streams (--format=raw), specify the filter chain in the same order as it was specified when compressing.
Filters take filter-specific options as a comma-separated list. Extra commas in options are ignored. Every option has a default value, so you need to specify only those you want to change.
LZMA1 is a legacy filter, which is supported almost solely due to the legacy .lzma file format, which supports only LZMA1. LZMA2 is an updated version of LZMA1 to fix some practical issues of LZMA1. The .xz format uses LZMA2 and doesn't support LZMA1 at all. Compression speed and ratios of LZMA1 and LZMA2 are practically the same.
LZMA1 and LZMA2 share the same set of options:
Typical dictionary size is from 64 KiB to 64 MiB. The minimum is 4 KiB. The maximum for compression is currently 1.5 GiB (1536 MiB). The decompressor already supports dictionaries up to one byte less than 4 GiB, which is the maximum for the LZMA1 and LZMA2 stream formats.
Dictionary size and match finder (mf) together determine the memory usage of the LZMA1 or LZMA2 encoder. The same (or bigger) dictionary size is required for decompressing than was used when compressing, thus the memory usage of the decoder is determined by the dictionary size used when compressing. The .xz headers store the dictionary size either as 2n or 2n + 2(n-1), so these sizes are somewhat preferred for compression. Other sizes will get rounded up when stored in the .xz headers.
All bytes that can't be encoded as matches are encoded as literals. That is, literals are simply 8-bit bytes that are encoded one at a time.
The literal coding makes an assumption that the highest lc bits of the previous uncompressed byte correlate with the next byte. For example, in typical English text, an uppercase letter is often followed by a lowercase letter, and a lowercase letter is usually followed by another lowercase letter. In the US-ASCII character set, the highest three bits are 010 for uppercase letters and 011 for lowercase letters. When lc is at least 3, the literal coding can take advantage of this property in the uncompressed data.
The default value (3) is usually good. If you want maximum compression, test lc=4. Sometimes it helps a little, and sometimes it makes compression worse. If it makes it worse, test (for example) lc=2 too.
The lp option affects what kind of alignment in the uncompressed data is assumed when encoding literals. See pb, below, for more information about alignment.
The pb option affects what kind of alignment in the uncompressed data is assumed in general. The default means four-byte alignment (2pb = 22 = 4), which is often a good choice when there's no better guess.
When the aligment is known, setting pb accordingly may reduce the file size a little. For example, with text files having one-byte alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can improve compression slightly. For UTF-16 text, pb=1 is a good choice. If the alignment is an odd number like 3 bytes, pb=0 might be the best choice.
Even though the assumed alignment can be adjusted with pb and lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment. It might be worth taking into account when designing file formats that are likely to be often compressed with LZMA1 or LZMA2.
The following match finders are supported. The memory usage formulas below are rough approximations, which are closest to the reality when dict is a power of two.
dict * 7.5 (if dict <= 16 MiB);
dict * 5.5 + 64 MiB (if dict > 16 MiB)
dict * 7.5 (if dict <= 32 MiB);
dict * 6.5 (if dict > 32 MiB)
dict * 11.5 (if dict <= 16 MiB);
dict * 9.5 + 64 MiB (if dict > 16 MiB)
dict * 11.5 (if dict <= 32 MiB);
dict * 10.5 (if dict > 32 MiB)
Usually fast is used with Hash Chain match finders and normal with Binary Tree match finders. This is also what the presets do.
Nice can be 2–273 bytes. Higher values tend to give better compression ratio at the expense of speed. The default depends on the preset.
Reasonable depth for Hash Chains is 4–100 and 16–1000 for Binary Trees. Using very high values for depth can make the encoder extremely slow with some files. Avoid setting the depth over 1000 unless you are prepared to interrupt the compression in case it is taking far too long.
When decoding raw streams (--format=raw), LZMA2 needs only the dictionary size. LZMA1 needs also lc, lp, and pb.
A BCJ filter converts relative addresses in the machine code to their absolute counterparts. This doesn't change the size of the data, but it increases redundancy, which can help LZMA2 to produce 0–15% smaller .xz file. The BCJ filters are always reversible, so using a BCJ filter for wrong type of data doesn't cause any data loss, although it may make the compression ratio slightly worse.
It's fine to apply a BCJ filter on a whole executable; there's no need to apply it only on the executable section. Applying a BCJ filter on an archive that contains both executable and nonexecutable files may or may not give good results, so it generally isn't good to blindly apply a BCJ filter when compressing binary packages for distribution.
These BCJ filters are very fast and use insignificant amount of memory. If a BCJ filter improves compression ratio of a file, it can improve decompression speed at the same time. This is because, on the same hardware, the decompression speed of LZMA2 is roughly a fixed number of bytes of compressed data per second.
These BCJ filters have known problems related to the compression ratio:
Both of the above problems will be fixed in the future in a new filter. The old BCJ filters will still be useful in embedded systems, because the decoder of the new filter will be bigger and use more memory.
Different instruction sets have have different alignment:
Filter | Alignment | Notes |
---|---|---|
x86 | 1 | 32-bit or 64-bit x86 |
ARM | 4 | Little endian only |
Since the BCJ-filtered data is usually compressed with LZMA2, the compression ratio may be improved slightly if the LZMA2 options are set to match the alignment of the selected BCJ filter. For example, with the IA-64 filter, it's good to set pb=4 with LZMA2 (24 = 16). The x86 filter is an exception; it's usually good to stick to LZMA2's default four-byte alignment when compressing x86 executables.
All BCJ filters support the same options:
Currently only simple byte-wise delta calculation is supported. It can be useful when compressing e.g., uncompressed bitmap images or uncompressed PCM audio. However, special purpose algorithms may give significantly better results than Delta + LZMA2.
Supported options:
For example, with dist=2 and eight-byte input A1 B1 A2 B3 A3 B5 A4 B7, the output will be A1 B1 01 02 01 02 01 02.
Other options
The progress indicator shows the following information:
When standard error isn't a terminal, --verbose will make xz print the filename, compressed size, uncompressed size, compression ratio, and possibly also the speed and elapsed time on a single line to standard error after compressing or decompressing the file. The speed and elapsed time are included only when the operation took at least a few seconds. If the operation didn't finish (e.g., due to user interruption), also the completion percentage is printed if the size of the input file is known.
The xz utility is a general-purpose data compression tool with command-line syntax similar to gzip and bzip2. The native file format is the .xz format, but the legacy .lzma format used by LZMA Utils and raw compressed streams with no container format headers are also supported.
The xz utility compresses or decompresses each file according to the selected operation mode. If no files are given or file is -, xz reads from standard input and writes the processed data to standard output. The xz utility refuses to write compressed data to standard output if it's a terminal; instead it displays an error and skips the file. Similarly, xz refuses to read compressed data from standard input if it's a terminal.
Unless you specify --stdout, files other than - are written to a new file whose name is derived from the source file name:
If the target file already exists, an error is displayed and the file is skipped.
Unless writing to standard output, xz will display a warning and skip the file if any of the following applies:
After successfully compressing or decompressing the file, xz copies the owner, group, permissions, access time, and modification time from the source file to the target file. If copying the group fails, the permissions are modified so that the target file doesn't become accessible to users who didn't have permission to access the source file. The xz utility doesn't yet support copying other metadata like access control lists or extended attributes.
Once the target file has been successfully closed, the source file is removed unless you specified --keep. The source file is never removed if the output is written to standard output.
Sending SIGINFO or SIGUSR1 to the xz process makes it print progress information to standard error. This has only limited use since when standard error is a terminal, using --verbose displays an automatically updating progress indicator.
The memory usage of xz varies from a few hundred kilobytes to several gigabytes, depending on the compression settings. The settings used when compressing a file determine the memory requirements of the decompressor. Typically the decompressor needs 5% to 20% of the amount of memory that the compressor needed when creating the file. For example, decompressing a file created with xz -9 currently requires 65 MiB of memory. Still, it's possible to have .xz files that require several gigabytes of memory to decompress.
Especially users of older systems may find the possibility of very large memory usage annoying. To prevent uncomfortable surprises, xz has a built-in memory usage limiter, which is disabled by default.
You can enable the memory usage limiter with the command-line option --memlimit=limit. Often it's more convenient to enable the limiter by default by setting the environment variable XZ_DEFAULTS (e.g., XZ_DEFAULTS=--memlimit=150MiB). It's possible to set the limits separately for compression and decompression by using --memlimit-compress=limit and --memlimit-decompress=limit. Using these two options outside XZ_DEFAULTS is rarely useful because a single run of xz can't do both compression and decompression, and --memlimit=limit (or -M limit) is shorter to type on the command line.
If the specified memory usage limit is exceeded when decompressing, xz will display an error and decompressing the file will fail. If the limit is exceeded when compressing, xz will try to scale the settings down so that the limit is no longer exceeded (except when using --format=raw or --no-adjust). This way the operation won't fail unless the limit is very small. The scaling of the settings is done in steps that don't match the compression level presets; for example, if the limit is only slightly less than the amount required for xz -9, the settings will be scaled down only a little, not all the way down to xz -8.
It's possible to concatenate .xz files as is. The xz utility will decompress such files as if they were a single .xz file.
It's possible to insert padding between the concatenated parts or after the last part. The padding must consist of null bytes, and the size of the padding must be a multiple of four bytes. This can be useful (for example) if the .xz file is stored on a medium that measures file sizes in 512-byte blocks.
Concatenation and padding aren't allowed with .lzma files or raw streams.
The robot mode is activated with the --robot option. It makes the output of xz easier to parse by other programs. Currently --robot is supported only together with --version, --info-memory, and --list. It will be supported for normal compression and decompression in the future.
Version
xz --robot --version will print the version number of xz and liblzma in the following format:
XZ_VERSION=XYYYZZZS LIBLZMA_VERSION=XYYYZZZS
The elements are as follows:
XYYYZZZS is the same on both lines if xz and liblzma are from the same XZ Utils release.
Examples: 4.999.9beta is 49990091 and 5.0.0 is 50000002.
Memory limit information
xz --robot --info-memory prints a single line with three tab-separated columns:
In the future, the output of xz --robot --info-memory may have more columns, but never more than a single line.
List mode
xz --robot --list uses tab-separated output. The first column of every line has a string that indicates the type of the information found on that line:
The columns of the file lines:
The columns of the stream lines:
The columns of the block lines:
If --verbose was specified twice, additional columns are included on the block lines. These aren't displayed with a single --verbose, because getting this information requires many seeks and can thus be slow:
The columns of the totals line:
If --verbose was specified twice, additional columns are included on the totals line:
Future versions may add new line types and new columns can be added to the existing line types, but the existing columns won't be changed.
The xz utility parses space-separated lists of options from the environment variables XZ_DEFAULTS and XZ_OPT, in this order, before parsing the options from the command line. Note that only options are parsed from the environment variables; all non-options are silently ignored. Parsing is done with getopt_long(), which is used also for the command-line arguments.
XZ_OPT=-2v tar caf foo.tar.xz foo
Scripts may use XZ_OPT, for example, to set script-specific default compression options. It is still recommended to allow users to override XZ_OPT if that is reasonable. For example, in sh scripts you may use something like this:
XZ_OPT=${XZ_OPT-"-7e"} export XZ_OPT
The command-line syntax of xz is practically a superset of lzma, unlzma, and lzcat as found from LZMA Utils 4.32.x. In most cases, it's possible to replace LZMA Utils with XZ Utils without breaking existing scripts. There are some incompatibilities though, which may sometimes cause problems.
Level xz LZMA Utils
-0 256 KiB N/A
-1 1 MiB 64 KiB
-2 2 MiB 1 MiB
-3 4 MiB 512 KiB
-4 4 MiB 1 MiB
-5 8 MiB 2 MiB
-6 8 MiB 4 MiB
-7 16 MiB 8 MiB
-8 32 MiB 16 MiB
-9 64 MiB 32 MiB
The dictionary size differences affect the compressor memory usage too, but there are some other differences between LZMA Utils and XZ Utils, which make the difference even bigger:
Level xz LZMA Utils 4.32.x
-0 3 MiB N/A
-1 9 MiB 2 MiB
-2 17 MiB 12 MiB
-3 32 MiB 12 MiB
-4 48 MiB 16 MiB
-5 94 MiB 26 MiB
-6 94 MiB 45 MiB
-7 186 MiB 83 MiB
-8 370 MiB 159 MiB
-9 674 MiB 311 MiB
The default preset level in LZMA Utils is -7, while in XZ Utils it's -6, so both use an 8 MiB dictionary by default.
xz supports decompressing .lzma files with or without end-of-payload marker, but all .lzma files created by xz will use end-of-payload marker and have uncompressed size marked as unknown in the .lzma header. This may be a problem in some uncommon situations. For example, a .lzma decompressor in an embedded device might work only with files that have known uncompressed size. If you hit this problem, you need to use LZMA Utils or LZMA SDK to create .lzma files with known uncompressed size.
The implementation of the LZMA1 filter in liblzma requires that the sum of lc and lp must not exceed 4. Thus, .lzma files, which exceed this limitation, can't be decompressed with xz.
LZMA Utils creates only .lzma files that have a dictionary size of 2n (a power of 2) but accepts files with any dictionary size. The liblzma library accepts only .lzma files that have a dictionary size of 2n or 2n + 2(n-1). This is to decrease false positives when detecting .lzma files.
These limitations shouldn't be a problem in practice, since practically all .lzma files have been compressed with settings that liblzma will accept.
If there's data left after the first .lzma stream, xz considers the file to be corrupt. This may break obscure scripts which have assumed that trailing garbage is ignored.
The above means that implementing --rsyncable to create rsyncable .xz files isn't going to happen without freezing a part of the encoder implementation, which can then be used with --rsyncable.
Outside embedded systems, all .xz format decompressors support all the check types, or at least are able to decompress the file without verifying the integrity check if the particular check isn't supported.
XZ Embedded supports BCJ filters, but only with the default start offset.
Basics
Compress the file foo into foo.xz using the default compression level (-6), and remove foo if compression is successful:
xz foo
Decompress bar.xz into bar and don't remove bar.xz, even if decompression is successful:
xz -dk bar.xz
Create baz.tar.xz with the preset -4e (-4 --extreme), which is slower than the default -6, but needs less memory for compression and decompression (48 MiB and 5 MiB, respectively):
tar cf - baz | xz -4e > baz.tar.xz
A mix of compressed and uncompressed files can be decompressed to standard output with a single command:
xz -dcf a.txt b.txt.xz c.txt d.txt.lzma > abcd.txt
Parallel compression of many files
On GNU and *BSD, find and xargs can be used to parallelize the compression of many files:
find . -type f \! -name '*.xz' -print0 | xargs -0r -P4 -n16 xz -T1
The -P option to xargs sets the number of parallel xz processes. The best value for the -n option depends on how many files there are to be compressed. If there are only a couple of files, the value should probably be 1; with tens of thousands of files, 100 or even more may be appropriate to reduce the number of xz processes that xargs will eventually create.
The option -T1 for xz is there to force it to single-threaded mode, because xargs is used to control the amount of parallelization.
Robot mode
Calculate how many bytes have been saved in total after compressing multiple files:
xz --robot --list *.xz | awk '/^totals/{print $5-$4}'
A script may want to know that it is using a new-enough version of xz. The following sh script checks that the version number of the xz tool is at least 5.0.0. This method is compatible with old beta versions, which didn't support the --robot option:
if ! eval "$(xz --robot --version 2> /dev/null)" || [ "$XZ_VERSION" -lt 50000002 ]; then echo "Your xz is too old." fi unset XZ_VERSION LIBLZMA_VERSION
Set a memory usage limit for decompression using XZ_OPT, but if a limit has already been set, don't increase it:
NEWLIM=$((123 << 20)) # 123 MiB OLDLIM=$(xz --robot --info-memory | cut -f3) if [ $OLDLIM -eq 0 -o $OLDLIM -gt $NEWLIM ]; then XZ_OPT="$XZ_OPT --memlimit-decompress=$NEWLIM" export XZ_OPT fi
Custom compressor filter chains
The simplest use for custom filter chains is customizing a LZMA2 preset. This can be useful, because the presets cover only a subset of the potentially useful combinations of compression settings.
The CompCPU columns of the tables from the descriptions of the options -0 ... -9 and --extreme are useful when customizing LZMA2 presets. Here are the relevant parts collected from those two tables:
Preset CompCPU
-0 0
-1 1
-2 2
-3 3
-4 4
-5 5
-6 6
-5e 7
-6e 8
If you know that a file requires somewhat big dictionary (e.g., 32 MiB) to compress well, but you want to compress it quicker than xz -8 would do, a preset with a low CompCPU value (e.g. 1) can be modified to use a bigger dictionary:
xz --lzma2=preset=1,dict=32MiB foo.tar
With certain files, the above command may be faster than xz -6 while compressing significantly better. However, it must be emphasized that only some files benefit from a big dictionary while keeping the CompCPU value low. The most obvious situation, where a big dictionary can help a lot, is an archive containing very similar files of at least a few megabytes each. The dictionary size has to be significantly bigger than any individual file to allow LZMA2 to take full advantage of the similarities between consecutive files.
If very high compressor and decompressor memory usage is fine, and the file being compressed is at least several hundred megabytes, it may be useful to use an even bigger dictionary than the 64 MiB that xz -9 would use:
xz -vv --lzma2=dict=192MiB big_foo.tar
Using -vv (--verbose --verbose) like in the above example can be useful to see the memory requirements of the compressor and decompressor. Remember that using a dictionary bigger than the size of the uncompressed file is waste of memory, so the above command isn't useful for small files.
Sometimes the compression time doesn't matter, but the decompressor memory usage has to be kept low e.g., to make it possible to decompress the file on an embedded system. The following command uses -6e (-6 --extreme) as a base and sets the dictionary to only 64 KiB. The resulting file can be decompressed with XZ Embedded (that's why there is --check=crc32) using about 100 KiB of memory.
xz --check=crc32 --lzma2=preset=6e,dict=64KiB foo
If you want to squeeze out as many bytes as possible, adjusting the number of literal context bits (lc) and number of position bits (pb) can sometimes help. Adjusting the number of literal position bits (lp) might help too, but usually lc and pb are more important. For example, a source code archive contains mostly US-ASCII text, so something like the following might give slightly (like 0.1 %) smaller file than xz -6e (try also without lc=4):
xz --lzma2=preset=6e,pb=0,lc=4 source_code.tar
Using another filter together with LZMA2 can improve compression with certain file types. For example, to compress a x86-32 or x86-64 shared library using the x86 BCJ filter:
xz --x86 --lzma2 libfoo.so
Note that the order of the filter options is significant. If --x86 is specified after --lzma2, xz will give an error, because there can't be any filter after LZMA2, and also because the x86 BCJ filter can't be used as the last filter in the chain.
The Delta filter together with LZMA2 can give good results with bitmap images. It should usually beat PNG, which has a few more advanced filters than simple delta but uses Deflate for the actual compression.
The image has to be saved in uncompressed format, e.g. as uncompressed TIFF. The distance parameter of the Delta filter is set to match the number of bytes per pixel in the image. E.g. 24-bit RGB bitmap needs dist=3, and it is also good to pass pb=0 to LZMA2 to accommodate the three-byte alignment:
xz --delta=dist=3 --lzma2=pb=0 foo.tiff
If multiple images have been put into a single archive (e.g. .tar), the Delta filter will work on that too as long as all images have the same number of bytes per pixel.
Notices (not warnings or errors) printed on standard error don't affect the exit status.
The XZ Utils were developed and are maintained by Lasse Collin; see http://tukaani.org/.