summaryrefslogtreecommitdiffstats
path: root/doc/lzip.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/lzip.texi')
-rw-r--r--doc/lzip.texi326
1 files changed, 167 insertions, 159 deletions
diff --git a/doc/lzip.texi b/doc/lzip.texi
index b22337e..144b525 100644
--- a/doc/lzip.texi
+++ b/doc/lzip.texi
@@ -6,10 +6,10 @@
@finalout
@c %**end of header
-@set UPDATED 4 January 2021
-@set VERSION 1.22
+@set UPDATED 24 January 2022
+@set VERSION 1.23
-@dircategory Data Compression
+@dircategory Compression
@direntry
* Lzip: (lzip). LZMA lossless data compressor
@end direntry
@@ -40,8 +40,8 @@ This manual is for Lzip (version @value{VERSION}, @value{UPDATED}).
* Output:: Meaning of lzip's output
* Invoking lzip:: Command line interface
* Quality assurance:: Design, development, and testing of lzip
-* File format:: Detailed format of the compressed file
* Algorithm:: How lzip compresses the data
+* File format:: Detailed format of the compressed file
* Stream format:: Format of the LZMA stream in lzip files
* Trailing data:: Extra data appended to the file
* Examples:: A small tutorial with examples
@@ -51,7 +51,7 @@ This manual is for Lzip (version @value{VERSION}, @value{UPDATED}).
@end menu
@sp 1
-Copyright @copyright{} 2008-2021 Antonio Diaz Diaz.
+Copyright @copyright{} 2008-2022 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy,
distribute, and modify it.
@@ -65,13 +65,14 @@ distribute, and modify it.
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
is a lossless data compressor with a user interface similar to the one
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
-chain-Algorithm' (LZMA) stream format, chosen to maximize safety and
-interoperability. Lzip can compress about as fast as gzip @w{(lzip -0)} or
-compress most files more than bzip2 @w{(lzip -9)}. Decompression speed is
-intermediate between gzip and bzip2. Lzip is better than gzip and bzip2 from
-a data recovery perspective. Lzip has been designed, written, and tested
-with great care to replace gzip and bzip2 as the standard general-purpose
-compressed format for unix-like systems.
+chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity
+checking to maximize interoperability and optimize safety. Lzip can compress
+about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2
+@w{(lzip -9)}. Decompression speed is intermediate between gzip and bzip2.
+Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip
+has been designed, written, and tested with great care to replace gzip and
+bzip2 as the standard general-purpose compressed format for unix-like
+systems.
For compressing/decompressing large files on multiprocessor machines
@uref{http://www.nongnu.org/lzip/manual/plzip_manual.html,,plzip} can be
@@ -81,8 +82,8 @@ much faster than lzip at the cost of a slightly reduced compression ratio.
@end ifnothtml
For creation and manipulation of compressed tar archives
-@uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} can be
-more efficient than using tar and plzip because tarlz is able to keep the
+@uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} can be more
+efficient than using tar and plzip because tarlz is able to keep the
alignment between tar members and lzip members.
@ifnothtml
@xref{Top,tarlz manual,,tarlz}.
@@ -123,7 +124,7 @@ the beginning is a thing of the past.
The member trailer stores the 32-bit CRC of the original data, the size
of the original data, and the size of the member. These values, together
-with the end-of-stream marker, provide a 3 factor integrity checking
+with the "End Of Stream" marker, provide a 3 factor integrity checking
which guarantees that the decompressed version of the data is identical
to the original. This guards against corruption of the compressed data,
and against undetected bugs in lzip (hopefully very unlikely). The
@@ -159,9 +160,9 @@ file from that of the compressed file as follows:
@item anyothername @tab becomes @tab anyothername.out
@end multitable
-(De)compressing a file is much like copying or moving it; therefore lzip
+(De)compressing a file is much like copying or moving it. Therefore lzip
preserves the access and modification dates, permissions, and, when
-possible, ownership of the file just as @samp{cp -p} does. (If the user ID or
+possible, ownership of the file just as @w{@samp{cp -p}} does. (If the user ID or
the group ID can't be duplicated, the file permission bits S_ISUID and
S_ISGID are cleared).
@@ -299,10 +300,12 @@ and @samp{-S}. @samp{-c} has no effect when testing or listing.
@item -d
@itemx --decompress
-Decompress the files specified. If a file does not exist or can't be
-opened, lzip continues decompressing the rest of the files. If a file
-fails to decompress, or is a terminal, lzip exits immediately without
-decompressing the rest of the files.
+Decompress the files specified. If a file does not exist, can't be opened,
+or the destination file already exists and @samp{--force} has not been
+specified, lzip continues decompressing the rest of the files and exits with
+error status 1. If a file fails to decompress, or is a terminal, lzip exits
+immediately with error status 2 without decompressing the rest of the files.
+A terminal is considered an uncompressed file, and therefore invalid.
@item -f
@itemx --force
@@ -327,10 +330,11 @@ size, the number of members in the file, and the amount of trailing data (if
any) are also printed. With @samp{-vv}, the positions and sizes of each
member in multimember files are also printed.
-@samp{-lq} can be used to verify quickly (without decompressing) the
-structural integrity of the files specified. (Use @samp{--test} to verify
-the data integrity). @samp{-alq} additionally verifies that none of the
-files specified contain trailing data.
+If any file is damaged, does not exist, can't be opened, or is not regular,
+the final exit status will be @w{> 0}. @samp{-lq} can be used to verify
+quickly (without decompressing) the structural integrity of the files
+specified. (Use @samp{--test} to verify the data integrity). @samp{-alq}
+additionally verifies that none of the files specified contain trailing data.
@item -m @var{bytes}
@itemx --match-length=@var{bytes}
@@ -473,9 +477,9 @@ Table of SI and binary prefixes (unit multipliers):
@sp 1
Exit status: 0 for a normal exit, 1 for environmental problems (file not
-found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or
-invalid input file, 3 for an internal consistency error (eg, bug) which
-caused lzip to panic.
+found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid
+input file, 3 for an internal consistency error (e.g., bug) which caused
+lzip to panic.
@node Quality assurance
@@ -629,11 +633,12 @@ and may limit the number of members or the total uncompressed size.
@table @samp
@item Accurate and robust error detection
-The lzip format provides 3 factor integrity checking and the decompressors
-report mismatches in each factor separately. This way if just one byte in
-one factor fails but the other two factors match the data, it probably means
-that the data are intact and the corruption just affects the mismatching
-factor (CRC or data size) in the check sequence.
+The lzip format provides 3 factor integrity checking, and the decompressors
+report mismatches in each factor separately. This method detects most false
+positives for corruption. If just one byte in one factor fails but the other
+two factors match the data, it probably means that the data are intact and
+the corruption just affects the mismatching factor (CRC, data size, or
+member size) in the member trailer.
@item Multiple implementations
@@ -672,84 +677,6 @@ into the design of gzip. Both bzip2 and lzip are free from this flaw.
@end table
-@node File format
-@chapter File format
-@cindex file format
-
-Perfection is reached, not when there is no longer anything to add, but
-when there is no longer anything to take away.@*
---- Antoine de Saint-Exupery
-
-@sp 1
-In the diagram below, a box like this:
-
-@verbatim
-+---+
-| | <-- the vertical bars might be missing
-+---+
-@end verbatim
-
-represents one byte; a box like this:
-
-@verbatim
-+==============+
-| |
-+==============+
-@end verbatim
-
-represents a variable number of bytes.
-
-@sp 1
-A lzip file consists of a series of "members" (compressed data sets).
-The members simply appear one after another in the file, with no
-additional information before, between, or after them.
-
-Each member has the following structure:
-
-@verbatim
-+--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-| ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size |
-+--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-@end verbatim
-
-All multibyte values are stored in little endian order.
-
-@table @samp
-@item ID string (the "magic" bytes)
-A four byte string, identifying the lzip format, with the value "LZIP"
-(0x4C, 0x5A, 0x49, 0x50).
-
-@item VN (version number, 1 byte)
-Just in case something needs to be modified in the future. 1 for now.
-
-@anchor{coded-dict-size}
-@item DS (coded dictionary size, 1 byte)
-The dictionary size is calculated by taking a power of 2 (the base size)
-and subtracting from it a fraction between 0/16 and 7/16 of the base size.@*
-Bits 4-0 contain the base 2 logarithm of the base size (12 to 29).@*
-Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract
-from the base size to obtain the dictionary size.@*
-Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@*
-Valid values for dictionary size range from 4 KiB to 512 MiB.
-
-@item LZMA stream
-The LZMA stream, finished by an end of stream marker. Uses default values
-for encoder properties. @xref{Stream format}, for a complete description.
-
-@item CRC32 (4 bytes)
-Cyclic Redundancy Check (CRC) of the uncompressed original data.
-
-@item Data size (8 bytes)
-Size of the uncompressed original data.
-
-@item Member size (8 bytes)
-Total size of the member, including header and trailer. This field acts
-as a distributed index, allows the verification of stream integrity, and
-facilitates safe recovery of undamaged members from multimember files.
-
-@end table
-
-
@node Algorithm
@chapter Algorithm
@cindex algorithm
@@ -766,7 +693,7 @@ of finding coding sequences of minimum size than the one currently used by
lzip could be developed, and the resulting sequence could also be coded
using the LZMA coding scheme.
-Lzip currently implements two variants of the LZMA algorithm; fast
+Lzip currently implements two variants of the LZMA algorithm: fast
(used by option @samp{-0}) and normal (used by all other compression levels).
The high compression of LZMA comes from combining two basic, well-proven
@@ -778,7 +705,7 @@ contexts according to what the bits are used for.
Lzip is a two stage compressor. The first stage is a Lempel-Ziv coder,
which reduces redundancy by translating chunks of data to their
corresponding distance-length pairs. The second stage is a range encoder
-that uses a different probability model for each type of data;
+that uses a different probability model for each type of data:
distances, lengths, literal bytes, etc.
Here is how it works, step by step:
@@ -825,32 +752,112 @@ encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
+@node File format
+@chapter File format
+@cindex file format
+
+Perfection is reached, not when there is no longer anything to add, but
+when there is no longer anything to take away.@*
+--- Antoine de Saint-Exupery
+
+@sp 1
+In the diagram below, a box like this:
+
+@verbatim
++---+
+| | <-- the vertical bars might be missing
++---+
+@end verbatim
+
+represents one byte; a box like this:
+
+@verbatim
++==============+
+| |
++==============+
+@end verbatim
+
+represents a variable number of bytes.
+
+@sp 1
+A lzip file consists of a series of independent "members" (compressed data
+sets). The members simply appear one after another in the file, with no
+additional information before, between, or after them. Each member can
+encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data.
+The size of a multimember file is unlimited.
+
+Each member has the following structure:
+
+@verbatim
++--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size |
++--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+@end verbatim
+
+All multibyte values are stored in little endian order.
+
+@table @samp
+@item ID string (the "magic" bytes)
+A four byte string, identifying the lzip format, with the value "LZIP"
+(0x4C, 0x5A, 0x49, 0x50).
+
+@item VN (version number, 1 byte)
+Just in case something needs to be modified in the future. 1 for now.
+
+@anchor{coded-dict-size}
+@item DS (coded dictionary size, 1 byte)
+The dictionary size is calculated by taking a power of 2 (the base size)
+and subtracting from it a fraction between 0/16 and 7/16 of the base size.@*
+Bits 4-0 contain the base 2 logarithm of the base size (12 to 29).@*
+Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract
+from the base size to obtain the dictionary size.@*
+Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@*
+Valid values for dictionary size range from 4 KiB to 512 MiB.
+
+@item LZMA stream
+The LZMA stream, finished by an "End Of Stream" marker. Uses default values
+for encoder properties. @xref{Stream format}, for a complete description.
+
+@item CRC32 (4 bytes)
+Cyclic Redundancy Check (CRC) of the original uncompressed data.
+
+@item Data size (8 bytes)
+Size of the original uncompressed data.
+
+@item Member size (8 bytes)
+Total size of the member, including header and trailer. This field acts
+as a distributed index, allows the verification of stream integrity, and
+facilitates the safe recovery of undamaged members from multimember files.
+Member size should be limited to @w{2 PiB} to prevent the data size field
+from overflowing.
+
+@end table
+
+
@node Stream format
@chapter Format of the LZMA stream in lzip files
@cindex format of the LZMA stream
-Lzip uses a simplified form of the LZMA stream format chosen to maximize
-safety and interoperability.
-
The LZMA algorithm has three parameters, called "special LZMA
properties", to adjust it for some kinds of binary data. These
-parameters are; @samp{literal_context_bits} (with a default value of 3),
+parameters are: @samp{literal_context_bits} (with a default value of 3),
@samp{literal_pos_state_bits} (with a default value of 0), and
@samp{pos_state_bits} (with a default value of 2). As a general purpose
compressor, lzip only uses the default values for these parameters. In
particular @samp{literal_pos_state_bits} has been optimized away and
does not even appear in the code.
-Lzip finishes the LZMA stream with an "End Of Stream" (EOS) marker
-(the distance-length pair 0xFFFFFFFFU, 2), which in conjunction with the
+Lzip finishes the LZMA stream with an "End Of Stream" (EOS) marker (the
+distance-length pair @w{0xFFFFFFFFU, 2}), which in conjunction with the
@samp{member size} field in the member trailer allows the verification of
-stream integrity. The LZMA stream in lzip files always has these two
-features (default properties and EOS marker) and is referred to in this
-document as LZMA-302eos. The EOS marker is the only marker allowed in
-lzip files.
+stream integrity. The EOS marker is the only marker allowed in lzip files.
+The LZMA stream in lzip files always has these two features (default
+properties and EOS marker) and is referred to in this document as
+LZMA-302eos. This simplified form of the LZMA stream format has been chosen
+to maximize interoperability and safety.
The second stage of LZMA is a range encoder that uses a different
-probability model for each type of symbol; distances, lengths, literal
+probability model for each type of symbol: distances, lengths, literal
bytes, etc. Range encoding conceptually encodes all the symbols of the
message into one number. Unlike Huffman coding, which assigns to each
symbol a bit-pattern and concatenates all the bit-patterns together,
@@ -858,16 +865,16 @@ range encoding can compress one symbol to less than one bit. Therefore
the compressed data produced by a range encoder can't be split in pieces
that could be described individually.
-It seems that the only way of describing the LZMA-302eos stream is
-describing the algorithm that decodes it. And given the many details
+It seems that the only way of describing the LZMA-302eos stream is to
+describe the algorithm that decodes it. And given the many details
about the range decoder that need to be described accurately, the source
-code of a real decoder seems the only appropriate reference to use.
+code of a real decompressor seems the only appropriate reference to use.
What follows is a description of the decoding algorithm for LZMA-302eos
streams using as reference the source code of "lzd", an educational
-decompressor for lzip files which can be downloaded from the lzip
-download directory. The source code of lzd is included in appendix A.
-@xref{Reference source code}.
+decompressor for lzip files which can be downloaded from the lzip download
+directory. Lzd is written in C++11 and its source code is included in
+appendix A. @xref{Reference source code}.
@sp 1
@section What is coded
@@ -905,7 +912,7 @@ Lengths (the @samp{len} in the table above) are coded as follows:
@end multitable
@sp 1
-The coding of distances is a little more complicated, so I'll begin
+The coding of distances is a little more complicated, so I'll begin by
explaining a simpler version of the encoding.
Imagine you need to encode a number from 0 to @w{2^32 - 1}, and you want to
@@ -915,7 +922,7 @@ which you may find by making a bit scan from the left (from the MSB). A
position of 0 means that the number is 0 (no bit is set), 1 means the LSB is
the first bit set (the number is 1), and 32 means the MSB is set (i.e., the
number is @w{>= 0x80000000}). Then, if the position is @w{>= 2}, you encode
-the remaining @w{position - 1} bits. Let's call these bits "direct_bits"
+the remaining @w{position - 1} bits. Let's call these bits "direct bits"
because they are coded directly by value instead of indirectly by position.
The inconvenient of this simple method is that it needs 6 bits to encode the
@@ -975,10 +982,10 @@ of 3. The resulting value is in the range 0 to 3.
@end table
-In the following table, @samp{!literal} is any sequence except a literal
-byte. @samp{rep} is any one of @samp{rep0}, @samp{rep1}, @samp{rep2}, or
-@samp{rep3}. The types of previous sequences corresponding to each state
-are:
+The types of previous sequences corresponding to each state are shown in the
+following table. @samp{!literal} is any sequence except a literal byte.
+@samp{rep} is any one of @samp{rep0}, @samp{rep1}, @samp{rep2}, or
+@samp{rep3}. The last type in each line is the most recent.
@multitable {State} {rep or (!literal, shortrep), literal, literal}
@headitem State @tab Types of previous sequences
@@ -1053,9 +1060,9 @@ The LZMA stream is consumed one byte at a time by the range decoder.
variable number of decoded bits, depending on how well these bits agree
with their context. (See @samp{decode_bit} in the source).
-The range decoder state consists of two unsigned 32-bit variables;
+The range decoder state consists of two unsigned 32-bit variables:
@samp{range} (representing the most significant part of the range size
-not yet decoded), and @samp{code} (representing the current point within
+not yet decoded) and @samp{code} (representing the current point within
@samp{range}). @samp{range} is initialized to @w{2^32 - 1}, and
@samp{code} is initialized to 0.
@@ -1069,14 +1076,15 @@ the source).
After decoding the member header and obtaining the dictionary size, the
range decoder is initialized and then the LZMA decoder enters a loop
-(See @samp{decode_member} in the source) where it invokes the range
+(see @samp{decode_member} in the source) where it invokes the range
decoder with the appropriate contexts to decode the different coding
sequences (matches, repeated matches, and literal bytes), until the "End
Of Stream" marker is decoded.
Once the "End Of Stream" marker has been decoded, the decompressor reads and
decodes the member trailer, and verifies that the three integrity factors
-(CRC, data size, and member size) match those calculated by the LZMA decoder.
+stored there (CRC, data size, and member size) match those computed from the
+data.
@node Trailing data
@@ -1165,7 +1173,7 @@ lzip -v file
@sp 1
@noindent
-Example 3: Like example 1 but the created @samp{file.lz} is multimember with
+Example 3: Like example 2 but the created @samp{file.lz} is multimember with
a member size of @w{1 MiB}. The compression ratio is not shown.
@example
@@ -1191,20 +1199,9 @@ lzip -tv file.lz
@end example
@sp 1
-@noindent
-Example 6: Compress a whole device in /dev/sdc and send the output to
-@samp{file.lz}.
-
-@example
- lzip -c /dev/sdc > file.lz
-or
- lzip /dev/sdc -o file.lz
-@end example
-
-@sp 1
@anchor{concat-example}
@noindent
-Example 7: The right way of concatenating the decompressed output of two or
+Example 6: The right way of concatenating the decompressed output of two or
more compressed files. @xref{Trailing data}.
@example
@@ -1216,7 +1213,7 @@ Do this instead
@sp 1
@noindent
-Example 8: Decompress @samp{file.lz} partially until @w{10 KiB} of
+Example 7: Decompress @samp{file.lz} partially until @w{10 KiB} of
decompressed data are produced.
@example
@@ -1225,7 +1222,7 @@ lzip -cd file.lz | dd bs=1024 count=10
@sp 1
@noindent
-Example 9: Decompress @samp{file.lz} partially from decompressed byte at
+Example 8: Decompress @samp{file.lz} partially from decompressed byte at
offset 10000 to decompressed byte at offset 14999 (5000 bytes are produced).
@example
@@ -1234,6 +1231,17 @@ lzip -cd file.lz | dd bs=1000 skip=10 count=5
@sp 1
@noindent
+Example 9: Compress a whole device in /dev/sdc and send the output to
+@samp{file.lz}.
+
+@example
+ lzip -c /dev/sdc > file.lz
+or
+ lzip /dev/sdc -o file.lz
+@end example
+
+@sp 1
+@noindent
Example 10: Create a multivolume compressed tar archive with a volume size
of @w{1440 KiB}.
@@ -1281,7 +1289,7 @@ find by running @w{@samp{lzip --version}}.
@verbatim
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2021 Antonio Diaz Diaz.
+ Copyright (C) 2013-2022 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -1311,7 +1319,7 @@ find by running @w{@samp{lzip --version}}.
#include <cstring>
#include <stdint.h>
#include <unistd.h>
-#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__)
+#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__
#include <fcntl.h>
#include <io.h>
#endif
@@ -1701,7 +1709,7 @@ int main( const int argc, const char * const argv[] )
"See the lzip manual for an explanation of the code.\n"
"\nUsage: %s [-d] < file.lz > file\n"
"Lzd decompresses from standard input to standard output.\n"
- "\nCopyright (C) 2021 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2022 Antonio Diaz Diaz.\n"
"License 2-clause BSD.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
@@ -1711,7 +1719,7 @@ int main( const int argc, const char * const argv[] )
return 0;
}
-#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__)
+#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__
setmode( STDIN_FILENO, O_BINARY );
setmode( STDOUT_FILENO, O_BINARY );
#endif