Applications 33 – XZ Compression – Longer Options Part One

J

Jarret W. Buse

Guest
Applications 33 – XZ Compression – Longer Options Part One

The “xz” compression utility has longer options which are for more advanced users. Be aware that these parameters do exist. This is the first article on the Longer Options.

The syntax for “xz” usage:

xz [parameters] [files]

The various parameters follow with examples.

  • --single-stream - decompress only the first stream ignoring all other data

As data is brought into the compression algorithm, it is streamed and everything is placed into blocks. The “xz” program only deals with one stream per file unless two files are joined.
Initially, let's make a multi-streamed file. First, make two text files named “FileA.txt” and “FileB.txt”. Place into each text file a line showing “This is File A.” and “This is File B.”, respectively. Now, you need to compress the two files with the commands “xz -zk FileA.txt” and “xz -zk FileB.txt”. Once the two are compressed, go to a terminal, change to the directory of the files we are making and enter the command “cat FileA.txt.xz + FileB.txt.xz > FileC.txt.xz”. The two files will be joined together to make a file called “FileC.txt.xz” which is also compressed. If you open the file and look at the file inside, “FileC.txt”, it should show “This is File A. This is File B.” (each being on a different line). To show that “FileC.txt.xz” has two streams now, type “xz -l FileC.txt.xz”.
So, to decompress the “FileC.txt.xz” file with only the first stream (“FileA.txt”), the command would be “xz -d --single-stream database.db.xz”. I now have a “FileC.txt” file with the contents being “This is file A.”. “FileC.txt” is an exact match to “FileA.txt” except the filename itself.

  • --no-sparse - do not create a sparse file when decompressing
Some large files may contain long strings of zeroes as filler, especially in databases. The filler could be skipped to preserve drive space. Use “--no-sparse” to not create the extra space in a file. For example, to uncompress the “database.db.xz” file and not to create a sparse file, the command would be “xz -d --no-sparse database.db.xz”.

  • -S (--suffix=.SUF) - use the suffix “.SUF” on compressed files

If you want to use a different extension other than the default “xz” suffix, you can specify it. The parameter is helpful for special made applications which will use compressed files, but the regular user should know the files are standard “xz” files. For example, if I needed the “database.db” file to be compressed and the suffix to be “.jwb”, the command would be “xz -z --suffix=.jwb database.db”.

  • --files[=FILE] - read filenames to process from FILE; if FILE is omitted, filenames are read from the standard input; filenames must be terminated with the newline character

Process a list of files stored in a text file, and these can be compressed or uncompressed as specified with a parameter. Each file name is terminated with a newline character. If, for example, I have a list of files to be compressed in a text file called “ToCompress.txt”, I could compress all files by using the command “xz -z --files=ToCompress.txt”.

  • --files0[=FILE] - like “--files” but use the null character as terminator for the file names

Process a list of files stored in a text file and these can be compressed or uncompressed as specified with a parameter. Each file name is terminated with a null character. An example is the same as the “--files=” example, except the parameter is “--files0=”.

  • -F (--format=FMT) - file format to encode or decode; possible values are “auto” (default), “xz”, “lzma”, and “raw”

The compression method can be specified with the “-F” option. Using the format of “xz” or “lzma” will cause the extension to be the same. In some cases, the “lzma” format can compress smaller than xz. If “raw” is used, then the option “suffix=” must be used. For example, to compress the “database.db” file using “raw”, the command would be “xz --format=raw --suffix=.raw database.db”.

  • -C (--check=CHECK) - integrity check type: “none” (use with caution), “crc32”, “crc64” (default), or “sha256”
When a compressed file is created, it includes a hash value to allow for an integrity check. The default is for a “crc64” hash value. It can be changed to “crc32”, “sha256” or even set to “none”. If “none” is used, then no hash is stored creating a slightly smaller file. To use a hash of “sha256” for the “database.db” file, the command would be “xz --check=sha256 database.db”.

  • --block-size=SIZE - when compressing to the .xz format, start a new block after every SIZE bytes of input; 0=disabled (default)

Since “xz” uses streams to compress data, each section of data is compressed individually as a block. To set the block size as 1,024 bytes for the “database.db” file, the command would be “xz --block-size=1024 database.db”.

This ends the first article on the Longer Options for the “xz” utility. Try these options out to be sure you understand their significance and use.
 

Attachments

  • slide.jpg
    slide.jpg
    32.9 KB · Views: 80,080

Members online


Latest posts

Top