"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "doc/lzlib.texi" between
lzlib-1.12.tar.lz and lzlib-1.13.tar.lz

About: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions using the lzip format.

lzlib.texi  (lzlib-1.12.tar.lz):lzlib.texi  (lzlib-1.13.tar.lz)
\input texinfo @c -*-texinfo-*- \input texinfo @c -*-texinfo-*-
@c %**start of header @c %**start of header
@setfilename lzlib.info @setfilename lzlib.info
@documentencoding ISO-8859-15 @documentencoding ISO-8859-15
@settitle Lzlib Manual @settitle Lzlib Manual
@finalout @finalout
@c %**end of header @c %**end of header
@set UPDATED 2 January 2021 @set UPDATED 23 January 2022
@set VERSION 1.12 @set VERSION 1.13
@dircategory Data Compression @dircategory Compression
@direntry @direntry
* Lzlib: (lzlib). Compression library for the lzip format * Lzlib: (lzlib). Compression library for the lzip format
@end direntry @end direntry
@ifnothtml @ifnothtml
@titlepage @titlepage
@title Lzlib @title Lzlib
@subtitle Compression library for the lzip format @subtitle Compression library for the lzip format
@subtitle for Lzlib version @value{VERSION}, @value{UPDATED} @subtitle for Lzlib version @value{VERSION}, @value{UPDATED}
@author by Antonio Diaz Diaz @author by Antonio Diaz Diaz
skipping to change at line 54 skipping to change at line 54
* Error codes:: Meaning of codes returned by functions * Error codes:: Meaning of codes returned by functions
* Error messages:: Error messages corresponding to error codes * Error messages:: Error messages corresponding to error codes
* Invoking minilzip:: Command line interface of the test program * Invoking minilzip:: Command line interface of the test program
* Data format:: Detailed format of the compressed data * Data format:: Detailed format of the compressed data
* Examples:: A small tutorial with examples * Examples:: A small tutorial with examples
* Problems:: Reporting bugs * Problems:: Reporting bugs
* Concept index:: Index of concepts * Concept index:: Index of concepts
@end menu @end menu
@sp 1 @sp 1
Copyright @copyright{} 2009-2021 Antonio Diaz Diaz. Copyright @copyright{} 2009-2022 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy, This manual is free documentation: you have unlimited permission to copy,
distribute, and modify it. distribute, and modify it.
@end ifnottex @end ifnottex
@node Introduction @node Introduction
@chapter Introduction @chapter Introduction
@cindex introduction @cindex introduction
@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib} @uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib}
skipping to change at line 78 skipping to change at line 78
Lzlib is written in C. Lzlib is written in C.
The lzip file format is designed for data sharing and long-term archiving, The lzip file format is designed for data sharing and long-term archiving,
taking into account both data integrity and decoder availability: taking into account both data integrity and decoder availability:
@itemize @bullet @itemize @bullet
@item @item
The lzip format provides very safe integrity checking and some data The lzip format provides very safe integrity checking and some data
recovery means. The program recovery means. The program
@uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lzi precover} @uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lzi precover}
can repair bit flip errors (one of the most common forms of data can repair bit flip errors (one of the most common forms of data corruption)
corruption) in lzip files, and provides data recovery capabilities, in lzip files, and provides data recovery capabilities, including
including error-checked merging of damaged copies of a file. error-checked merging of damaged copies of a file.
@ifnothtml @ifnothtml
@xref{Data safety,,,lziprecover}. @xref{Data safety,,,lziprecover}.
@end ifnothtml @end ifnothtml
@item @item
The lzip format is as simple as possible (but not simpler). The lzip The lzip format is as simple as possible (but not simpler). The lzip
manual provides the source code of a simple decompressor along with a manual provides the source code of a simple decompressor along with a
detailed explanation of how it works, so that with the only help of the detailed explanation of how it works, so that with the only help of the
lzip manual it would be possible for a digital archaeologist to extract lzip manual it would be possible for a digital archaeologist to extract
the data from a lzip file long after quantum computers eventually render the data from a lzip file long after quantum computers eventually
LZMA obsolete. render LZMA obsolete.
@item @item
Additionally the lzip reference implementation is copylefted, which Additionally the lzip reference implementation is copylefted, which
guarantees that it will remain free forever. guarantees that it will remain free forever.
@end itemize @end itemize
A nice feature of the lzip format is that a corrupt byte is easier to repair A nice feature of the lzip format is that a corrupt byte is easier to repair
the nearer it is from the beginning of the file. Therefore, with the help of the nearer it is from the beginning of the file. Therefore, with the help of
lziprecover, losing an entire archive just because of a corrupt byte near lziprecover, losing an entire archive just because of a corrupt byte near
the beginning is a thing of the past. the beginning is a thing of the past.
The functions and variables forming the interface of the compression library The functions and variables forming the interface of the compression library
are declared in the file @samp{lzlib.h}. Usage examples of the library are are declared in the file @samp{lzlib.h}. Usage examples of the library are
given in the files @samp{bbexample.c}, @samp{ffexample.c}, and @samp{main.c} given in the files @samp{bbexample.c}, @samp{ffexample.c}, and
from the source distribution. @samp{minilzip.c} from the source distribution.
All the library functions are thread safe. The library does not install any
signal handler. The decoder checks the consistency of the compressed data,
so the library should never crash even in case of corrupted input.
Compression/decompression is done by repeatedly calling a couple of Compression/decompression is done by repeatedly calling a couple of
read/write functions until all the data have been processed by the library. read/write functions until all the data have been processed by the library.
This interface is safer and less error prone than the traditional zlib This interface is safer and less error prone than the traditional zlib
interface. interface.
Compression/decompression is done when the read function is called. This Compression/decompression is done when the read function is called. This
means the value returned by the position functions will not be updated until means the value returned by the position functions will not be updated until
a read call, even if a lot of data are written. If you want the data to be a read call, even if a lot of data are written. If you want the data to be
compressed in advance, just call the read function with a @var{size} equal compressed in advance, just call the read function with a @var{size} equal
skipping to change at line 135 skipping to change at line 139
Lzlib will correctly decompress a data stream which is the concatenation of Lzlib will correctly decompress a data stream which is the concatenation of
two or more compressed data streams. The result is the concatenation of the two or more compressed data streams. The result is the concatenation of the
corresponding decompressed data streams. Integrity testing of concatenated corresponding decompressed data streams. Integrity testing of concatenated
compressed data streams is also supported. compressed data streams is also supported.
Lzlib is able to compress and decompress streams of unlimited size by Lzlib is able to compress and decompress streams of unlimited size by
automatically creating multimember output. The members so created are large, automatically creating multimember output. The members so created are large,
about @w{2 PiB} each. about @w{2 PiB} each.
All the library functions are thread safe. The library does not install
any signal handler. The decoder checks the consistency of the compressed
data, so the library should never crash even in case of corrupted input.
In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a
concrete algorithm; it is more like "any algorithm using the LZMA coding concrete algorithm; it is more like "any algorithm using the LZMA coding
scheme". For example, the option @samp{-0} of lzip uses the scheme in almost scheme". For example, the option @samp{-0} of lzip uses the scheme in almost the
the simplest way possible; issuing the longest match it can find, or a simplest way possible; issuing the longest match it can find, or a literal
literal byte if it can't find a match. Inversely, a much more elaborated way byte if it can't find a match. Inversely, a much more elaborated way of
of finding coding sequences of minimum size than the one currently used by finding coding sequences of minimum size than the one currently used by lzip
lzip could be developed, and the resulting sequence could also be coded could be developed, and the resulting sequence could also be coded using the
using the LZMA coding scheme. LZMA coding scheme.
Lzlib currently implements two variants of the LZMA algorithm; fast (used by Lzlib currently implements two variants of the LZMA algorithm: fast (used by
option @samp{-0} of minilzip) and normal (used by all other compression option @samp{-0} of minilzip) and normal (used by all other compression levels).
levels).
The high compression of LZMA comes from combining two basic, well-proven The high compression of LZMA comes from combining two basic, well-proven
compression ideas: sliding dictionaries (LZ77/78) and markov models (the compression ideas: sliding dictionaries (LZ77/78) and markov models (the
thing used by every compression algorithm that uses a range encoder or thing used by every compression algorithm that uses a range encoder or
similar order-0 entropy coder as its last stage) with segregation of similar order-0 entropy coder as its last stage) with segregation of
contexts according to what the bits are used for. contexts according to what the bits are used for.
The ideas embodied in lzlib are due to (at least) the following people: The ideas embodied in lzlib are due to (at least) the following people:
Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range definition of Markov chains), G.N.N. Martin (for the definition of range
skipping to change at line 176 skipping to change at line 175
the process of decompression. the process of decompression.
@node Library version @node Library version
@chapter Library version @chapter Library version
@cindex library version @cindex library version
One goal of lzlib is to keep perfect backward compatibility with older One goal of lzlib is to keep perfect backward compatibility with older
versions of itself down to 1.0. Any application working with an older lzlib versions of itself down to 1.0. Any application working with an older lzlib
should work with a newer lzlib. Installing a newer lzlib should not break should work with a newer lzlib. Installing a newer lzlib should not break
anything. This chapter describes the constants and functions that the anything. This chapter describes the constants and functions that the
application can use to discover the version of the library being used. application can use to discover the version of the library being used. All
of them are declared in @samp{lzlib.h}.
@defvr Constant LZ_API_VERSION @defvr Constant LZ_API_VERSION
This constant is defined in @samp{lzlib.h} and works as a version test This constant is defined in @samp{lzlib.h} and works as a version test
macro. The application should verify at compile time that LZ_API_VERSION is macro. The application should verify at compile time that LZ_API_VERSION is
greater than or equal to the version required by the application: greater than or equal to the version required by the application:
@example @example
#if !defined LZ_API_VERSION || LZ_API_VERSION < 1012 #if !defined LZ_API_VERSION || LZ_API_VERSION < 1012
#error "lzlib 1.12 or newer needed." #error "lzlib 1.12 or newer needed."
#endif #endif
skipping to change at line 364 skipping to change at line 364
@var{member_size}. @var{member_size}.
@end deftypefun @end deftypefun
@anchor{sync_flush} @anchor{sync_flush}
@deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} ) @deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} )
Use this function to make available to @samp{LZ_compress_read} all the data Use this function to make available to @samp{LZ_compress_read} all the data
already written with the function @samp{LZ_compress_write}. First call already written with the function @samp{LZ_compress_write}. First call
@samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it @samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it
returns 0. returns 0.
This function writes a LZMA marker @samp{3} ("Sync Flush" marker) to the This function writes at least one LZMA marker @samp{3} ("Sync Flush" marker)
compressed output. Note that the sync flush marker is not allowed in lzip to the compressed output. Note that the sync flush marker is not allowed in
files; it is a device for interactive communication between applications lzip files; it is a device for interactive communication between
using lzlib, but is useless and wasteful in a file, and is excluded from the applications using lzlib, but is useless and wasteful in a file, and is
media type @samp{application/lzip}. The LZMA marker @samp{2} ("End Of excluded from the media type @samp{application/lzip}. The LZMA marker
Stream" marker) is the only marker allowed in lzip files. @xref{Data format}. @samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files.
@xref{Data format}.
Repeated use of @samp{LZ_compress_sync_flush} may degrade compression Repeated use of @samp{LZ_compress_sync_flush} may degrade compression
ratio, so use it only when needed. If the interval between calls to ratio, so use it only when needed. If the interval between calls to
@samp{LZ_compress_sync_flush} is large (comparable to dictionary size), @samp{LZ_compress_sync_flush} is large (comparable to dictionary size),
creating a multimember data stream with @samp{LZ_compress_restart_member} creating a multimember data stream with @samp{LZ_compress_restart_member}
may be an alternative. may be an alternative.
Combining multimember stream creation with flushing may be tricky. If there Combining multimember stream creation with flushing may be tricky. If there
are more bytes available than those needed to complete @var{member_size}, are more bytes available than those needed to complete @var{member_size},
@samp{LZ_compress_restart_member} needs to be called when @samp{LZ_compress_restart_member} needs to be called when
@samp{LZ_compress_member_finished} returns 1, followed by a new call to @samp{LZ_compress_member_finished} returns 1, followed by a new call to
@samp{LZ_compress_sync_flush}. @samp{LZ_compress_sync_flush}.
@end deftypefun @end deftypefun
@deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint 8_t * const @var{buffer}, const int @var{size} ) @deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint 8_t * const @var{buffer}, const int @var{size} )
The function @samp{LZ_compress_read} reads up to @var{size} bytes from the Reads up to @var{size} bytes from the stream pointed to by @var{encoder},
stream pointed to by @var{encoder}, storing the results in @var{buffer}. storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which @var{buffer} may be a null pointer, in which case the bytes read are
case the bytes read are discarded. discarded.
The return value is the number of bytes actually read. This might be less Returns the number of bytes actually read. This might be less than
than @var{size}; for example, if there aren't that many bytes left in the @var{size}; for example, if there aren't that many bytes left in the stream
stream or if more bytes have to be yet written with the function or if more bytes have to be yet written with the function
@samp{LZ_compress_write}. Note that reading less than @var{size} bytes is @samp{LZ_compress_write}. Note that reading less than @var{size} bytes is
not an error. not an error.
@end deftypefun @end deftypefun
@deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uin t8_t * const @var{buffer}, const int @var{size} ) @deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uin t8_t * const @var{buffer}, const int @var{size} )
The function @samp{LZ_compress_write} writes up to @var{size} bytes from Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
@var{buffer} to the stream pointed to by @var{encoder}. @var{encoder}. Returns the number of bytes actually written. This might be
less than @var{size}. Note that writing less than @var{size} bytes is not an
The return value is the number of bytes actually written. This might be error.
less than @var{size}. Note that writing less than @var{size} bytes is
not an error.
@end deftypefun @end deftypefun
@deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} ) @deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} )
The function @samp{LZ_compress_write_size} returns the maximum number of Returns the maximum number of bytes that can be immediately written through
bytes that can be immediately written through @samp{LZ_compress_write}. @samp{LZ_compress_write}. For efficiency reasons, once the input buffer is
For efficiency reasons, once the input buffer is full and full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must
@samp{LZ_compress_write_size} returns 0, almost all the buffer must be be compressed before a size greater than 0 is returned again. (This is done
compressed before a size greater than 0 is returned again. (This is done to to minimize the amount of data that must be copied to the beginning of the
minimize the amount of data that must be copied to the beginning of the
buffer before new data can be accepted). buffer before new data can be accepted).
It is guaranteed that an immediate call to @samp{LZ_compress_write} will It is guaranteed that an immediate call to @samp{LZ_compress_write} will
accept a @var{size} up to the returned number of bytes. accept a @var{size} up to the returned number of bytes.
@end deftypefun @end deftypefun
@deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{e ncoder} ) @deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{e ncoder} )
Returns the current error code for @var{encoder}. @xref{Error codes}. Returns the current error code for @var{encoder}. @xref{Error codes}.
It is safe to call @samp{LZ_compress_errno} with a null argument, in which It is safe to call @samp{LZ_compress_errno} with a null argument, in which
case it returns @samp{LZ_bad_argument}. case it returns @samp{LZ_bad_argument}.
skipping to change at line 459 skipping to change at line 457
@deftypefun {unsigned long long} LZ_compress_total_out_size ( struct LZ_Encoder * const @var{encoder} ) @deftypefun {unsigned long long} LZ_compress_total_out_size ( struct LZ_Encoder * const @var{encoder} )
Returns the total number of compressed bytes already produced, but Returns the total number of compressed bytes already produced, but
perhaps not yet read. perhaps not yet read.
@end deftypefun @end deftypefun
@node Decompression functions @node Decompression functions
@chapter Decompression functions @chapter Decompression functions
@cindex decompression functions @cindex decompression functions
These are the functions used to decompress data. In case of error, all These are the functions used to decompress data. In case of error, all of
of them return -1 or 0, for signed and unsigned return values them return -1 or 0, for signed and unsigned return values respectively,
respectively, except @samp{LZ_decompress_open} whose return value must except @samp{LZ_decompress_open} whose return value must be verified by
be verified by calling @samp{LZ_decompress_errno} before using it. calling @samp{LZ_decompress_errno} before using it.
@deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void ) @deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void )
Initializes the internal stream state for decompression and returns a Initializes the internal stream state for decompression and returns a
pointer that can only be used as the @var{decoder} argument for the pointer that can only be used as the @var{decoder} argument for the
other LZ_decompress functions, or a null pointer if the decoder could other LZ_decompress functions, or a null pointer if the decoder could
not be allocated. not be allocated.
The returned pointer must be verified by calling The returned pointer must be verified by calling
@samp{LZ_decompress_errno} before using it. If @samp{LZ_decompress_errno} before using it. If
@samp{LZ_decompress_errno} does not return @samp{LZ_ok}, the returned @samp{LZ_decompress_errno} does not return @samp{LZ_ok}, the returned
skipping to change at line 514 skipping to change at line 512
written with @samp{LZ_decompress_write} will be consumed and written with @samp{LZ_decompress_write} will be consumed and
@samp{LZ_decompress_read} will return 0 until a header is found. @samp{LZ_decompress_read} will return 0 until a header is found.
This function is useful to discard any data preceding the first member, This function is useful to discard any data preceding the first member,
or to discard the rest of the current member, for example in case of a or to discard the rest of the current member, for example in case of a
data error. If the decoder is already at the beginning of a member, this data error. If the decoder is already at the beginning of a member, this
function does nothing. function does nothing.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, ui nt8_t * const @var{buffer}, const int @var{size} ) @deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, ui nt8_t * const @var{buffer}, const int @var{size} )
The function @samp{LZ_decompress_read} reads up to @var{size} bytes from the Reads up to @var{size} bytes from the stream pointed to by @var{decoder},
stream pointed to by @var{decoder}, storing the results in @var{buffer}. storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
If @w{LZ_API_VERSION >= 1012}, @var{buffer} may be a null pointer, in which @var{buffer} may be a null pointer, in which case the bytes read are
case the bytes read are discarded. discarded.
The return value is the number of bytes actually read. This might be less Returns the number of bytes actually read. This might be less than
than @var{size}; for example, if there aren't that many bytes left in the @var{size}; for example, if there aren't that many bytes left in the stream
stream or if more bytes have to be yet written with the function or if more bytes have to be yet written with the function
@samp{LZ_decompress_write}. Note that reading less than @var{size} bytes is @samp{LZ_decompress_write}. Note that reading less than @var{size} bytes is
not an error. not an error.
@samp{LZ_decompress_read} returns at least once per member so that @samp{LZ_decompress_read} returns at least once per member so that
@samp{LZ_decompress_member_finished} can be called (and trailer data @samp{LZ_decompress_member_finished} can be called (and trailer data
retrieved) for each member, even for empty members. Therefore, retrieved) for each member, even for empty members. Therefore,
@samp{LZ_decompress_read} returning 0 does not mean that the end of the @samp{LZ_decompress_read} returning 0 does not mean that the end of the
stream has been reached. The increase in the value returned by stream has been reached. The increase in the value returned by
@samp{LZ_decompress_total_in_size} can be used to tell the end of the stream @samp{LZ_decompress_total_in_size} can be used to tell the end of the stream
from an empty member. from an empty member.
skipping to change at line 545 skipping to change at line 543
application, but waits until all the bytes decoded have been read. This application, but waits until all the bytes decoded have been read. This
allows tools like allows tools like
@uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} to @uref{http://www.nongnu.org/lzip/manual/tarlz_manual.html,,tarlz} to
recover as much data as possible from each damaged member. recover as much data as possible from each damaged member.
@ifnothtml @ifnothtml
@xref{Top,tarlz manual,,tarlz}. @xref{Top,tarlz manual,,tarlz}.
@end ifnothtml @end ifnothtml
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, u int8_t * const @var{buffer}, const int @var{size} ) @deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, u int8_t * const @var{buffer}, const int @var{size} )
The function @samp{LZ_decompress_write} writes up to @var{size} bytes from Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
@var{buffer} to the stream pointed to by @var{decoder}. @var{decoder}. Returns the number of bytes actually written. This might be
less than @var{size}. Note that writing less than @var{size} bytes is not an
The return value is the number of bytes actually written. This might be error.
less than @var{size}. Note that writing less than @var{size} bytes is
not an error.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decode r} ) @deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decode r} )
The function @samp{LZ_decompress_write_size} returns the maximum number of Returns the maximum number of bytes that can be immediately written through
bytes that can be immediately written through @samp{LZ_decompress_write}. @samp{LZ_decompress_write}. This number varies smoothly; each compressed
This number varies smoothly; each compressed byte consumed may be byte consumed may be overwritten immediately, increasing by 1 the value
overwritten immediately, increasing by 1 the value returned. returned.
It is guaranteed that an immediate call to @samp{LZ_decompress_write} will It is guaranteed that an immediate call to @samp{LZ_decompress_write} will
accept a @var{size} up to the returned number of bytes. accept a @var{size} up to the returned number of bytes.
@end deftypefun @end deftypefun
@deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var {decoder} ) @deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var {decoder} )
Returns the current error code for @var{decoder}. @xref{Error codes}. Returns the current error code for @var{decoder}. @xref{Error codes}.
It is safe to call @samp{LZ_decompress_errno} with a null argument, in which It is safe to call @samp{LZ_decompress_errno} with a null argument, in which
case it returns @samp{LZ_bad_argument}. case it returns @samp{LZ_bad_argument}.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_finished ( struct LZ_Decoder * const @var{decoder} ) @deftypefun int LZ_decompress_finished ( struct LZ_Decoder * const @var{decoder} )
Returns 1 if all the data have been read and @samp{LZ_decompress_close} Returns 1 if all the data have been read and @samp{LZ_decompress_close}
can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished} can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished}
does not imply @samp{LZ_decompress_member_finished}. does not imply @samp{LZ_decompress_member_finished}.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{d ecoder} ) @deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{d ecoder} )
Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading
the current member, indicating that final values for member are available the current member, indicating that final values for the member are available
through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position}, through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position},
and @samp{LZ_decompress_member_position}. Otherwise it returns 0. and @samp{LZ_decompress_member_position}. Otherwise it returns 0.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_member_version ( struct LZ_Decoder * const @var{de coder} ) @deftypefun int LZ_decompress_member_version ( struct LZ_Decoder * const @var{de coder} )
Returns the version of current member from member header. Returns the version of the current member, read from the member header.
@end deftypefun @end deftypefun
@deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{d ecoder} ) @deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{d ecoder} )
Returns the dictionary size of the current member, read from the member Returns the dictionary size of the current member, read from the member header.
header.
@end deftypefun @end deftypefun
@deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{d ecoder} ) @deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{d ecoder} )
Returns the 32 bit Cyclic Redundancy Check of the data decompressed from Returns the 32 bit Cyclic Redundancy Check of the data decompressed from
the current member. The returned value is valid only when the current member. The value returned is valid only when
@samp{LZ_decompress_member_finished} returns 1. @samp{LZ_decompress_member_finished} returns 1.
@end deftypefun @end deftypefun
@deftypefun {unsigned long long} LZ_decompress_data_position ( struct LZ_Decoder * const @var{decoder} ) @deftypefun {unsigned long long} LZ_decompress_data_position ( struct LZ_Decoder * const @var{decoder} )
Returns the number of decompressed bytes already produced, but perhaps Returns the number of decompressed bytes already produced, but perhaps
not yet read, in the current member. not yet read, in the current member.
@end deftypefun @end deftypefun
@deftypefun {unsigned long long} LZ_decompress_member_position ( struct LZ_Decod er * const @var{decoder} ) @deftypefun {unsigned long long} LZ_decompress_member_position ( struct LZ_Decod er * const @var{decoder} )
Returns the number of input bytes already decompressed in the current member. Returns the number of input bytes already decompressed in the current member.
skipping to change at line 634 skipping to change at line 629
Library functions don't change the value returned by Library functions don't change the value returned by
@samp{LZ_(de)compress_errno} when they succeed; thus, the value returned @samp{LZ_(de)compress_errno} when they succeed; thus, the value returned
by @samp{LZ_(de)compress_errno} after a successful call is not by @samp{LZ_(de)compress_errno} after a successful call is not
necessarily LZ_ok, and you should not use @samp{LZ_(de)compress_errno} necessarily LZ_ok, and you should not use @samp{LZ_(de)compress_errno}
to determine whether a call failed. If the call failed, then you can to determine whether a call failed. If the call failed, then you can
examine @samp{LZ_(de)compress_errno}. examine @samp{LZ_(de)compress_errno}.
The error codes are defined in the header file @samp{lzlib.h}. The error codes are defined in the header file @samp{lzlib.h}.
@deftypevr Constant {enum LZ_Errno} LZ_ok @deftypevr Constant {enum LZ_Errno} LZ_ok
The value of this constant is 0 and is used to indicate that there is no The value of this constant is 0 and is used to indicate that there is no error.
error.
@end deftypevr @end deftypevr
@deftypevr Constant {enum LZ_Errno} LZ_bad_argument @deftypevr Constant {enum LZ_Errno} LZ_bad_argument
At least one of the arguments passed to the library function was invalid. At least one of the arguments passed to the library function was invalid.
@end deftypevr @end deftypevr
@deftypevr Constant {enum LZ_Errno} LZ_mem_error @deftypevr Constant {enum LZ_Errno} LZ_mem_error
No memory available. The system cannot allocate more virtual memory No memory available. The system cannot allocate more virtual memory
because its capacity is full. because its capacity is full.
@end deftypevr @end deftypevr
skipping to change at line 697 skipping to change at line 691
@end deftypefun @end deftypefun
@node Invoking minilzip @node Invoking minilzip
@chapter Invoking minilzip @chapter Invoking minilzip
@cindex invoking @cindex invoking
@cindex options @cindex options
Minilzip is a test program for the compression library lzlib, fully Minilzip is a test program for the compression library lzlib, fully
compatible with lzip 1.4 or newer. compatible with lzip 1.4 or newer.
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip} is a lossless data @uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
compressor with a user interface similar to the one of gzip or bzip2. Lzip is a lossless data compressor with a user interface similar to the one
uses a simplified form of the 'Lempel-Ziv-Markov chain-Algorithm' (LZMA) of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
stream format, chosen to maximize safety and interoperability. Lzip can chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity
compress about as fast as gzip @w{(lzip -0)} or compress most files more checking to maximize interoperability and optimize safety. Lzip can compress
than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between gzip about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2
and bzip2. Lzip is better than gzip and bzip2 from a data recovery @w{(lzip -9)}. Decompression speed is intermediate between gzip and bzip2.
perspective. Lzip has been designed, written, and tested with great care to Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip
replace gzip and bzip2 as the standard general-purpose compressed format for has been designed, written, and tested with great care to replace gzip and
unix-like systems. bzip2 as the standard general-purpose compressed format for unix-like
systems.
@noindent @noindent
The format for running minilzip is: The format for running minilzip is:
@example @example
minilzip [@var{options}] [@var{files}] minilzip [@var{options}] [@var{files}]
@end example @end example
@noindent @noindent
If no file names are specified, minilzip compresses (or decompresses) from If no file names are specified, minilzip compresses (or decompresses) from
skipping to change at line 763 skipping to change at line 758
Compress or decompress to standard output; keep input files unchanged. If Compress or decompress to standard output; keep input files unchanged. If
compressing several files, each file is compressed independently. (The compressing several files, each file is compressed independently. (The
output consists of a sequence of independently compressed members). This output consists of a sequence of independently compressed members). This
option (or @samp{-o}) is needed when reading from a named pipe (fifo) or option (or @samp{-o}) is needed when reading from a named pipe (fifo) or
from a device. Use it also to recover as much of the decompressed data as from a device. Use it also to recover as much of the decompressed data as
possible when decompressing a corrupt file. @samp{-c} overrides @samp{-o} possible when decompressing a corrupt file. @samp{-c} overrides @samp{-o}
and @samp{-S}. @samp{-c} has no effect when testing or listing. and @samp{-S}. @samp{-c} has no effect when testing or listing.
@item -d @item -d
@itemx --decompress @itemx --decompress
Decompress the files specified. If a file does not exist or can't be Decompress the files specified. If a file does not exist, can't be opened,
opened, minilzip continues decompressing the rest of the files. If a file or the destination file already exists and @samp{--force} has not been
fails to decompress, or is a terminal, minilzip exits immediately without specified, minilzip continues decompressing the rest of the files and exits with
decompressing the rest of the files. error status 1. If a file fails to decompress, or is a terminal, minilzip 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 @item -f
@itemx --force @itemx --force
Force overwrite of output files. Force overwrite of output files.
@item -F @item -F
@itemx --recompress @itemx --recompress
When compressing, force re-compression of files whose name already has When compressing, force re-compression of files whose name already has
the @samp{.lz} or @samp{.tlz} suffix. the @samp{.lz} or @samp{.tlz} suffix.
skipping to change at line 892 skipping to change at line 889
Aliases for GNU gzip compatibility. Aliases for GNU gzip compatibility.
@item --loose-trailing @item --loose-trailing
When decompressing or testing, allow trailing data whose first bytes are When decompressing or testing, allow trailing data whose first bytes are
so similar to the magic bytes of a lzip header that they can be confused so similar to the magic bytes of a lzip header that they can be confused
with a corrupt header. Use this option if a file triggers a "corrupt with a corrupt header. Use this option if a file triggers a "corrupt
header" error and the cause is not indeed a corrupt header. header" error and the cause is not indeed a corrupt header.
@item --check-lib @item --check-lib
Compare the @uref{#Library-version,,version of lzlib} used to compile Compare the @uref{#Library-version,,version of lzlib} used to compile
minilzip with the version actually being used and exit. Report any minilzip with the version actually being used at run time and exit. Report
differences found. Exit with error status 1 if differences are found. A any differences found. Exit with error status 1 if differences are found. A
mismatch may indicate that lzlib is not correctly installed or that a mismatch may indicate that lzlib is not correctly installed or that a
different version of lzlib has been installed after compiling the shared different version of lzlib has been installed after compiling the shared
version of minilzip. @w{@samp{minilzip -v --check-lib}} shows the version of version of minilzip. Exit with error status 2 if LZ_API_VERSION and
lzlib being used and the value of @samp{LZ_API_VERSION} (if defined). LZ_version_string don't match. @w{@samp{minilzip -v --check-lib}} shows the
version of lzlib being used and the value of LZ_API_VERSION (if defined).
@ifnothtml @ifnothtml
@xref{Library version}. @xref{Library version}.
@end ifnothtml @end ifnothtml
@end table @end table
Numbers given as arguments to options may be followed by a multiplier Numbers given as arguments to options may be followed by a multiplier
and an optional @samp{B} for "byte". and an optional @samp{B} for "byte".
Table of SI and binary prefixes (unit multipliers): Table of SI and binary prefixes (unit multipliers):
skipping to change at line 923 skipping to change at line 921
@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30) @item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30)
@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40) @item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40)
@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50) @item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50)
@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60) @item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60)
@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70) @item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70)
@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80) @item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80)
@end multitable @end multitable
@sp 1 @sp 1
Exit status: 0 for a normal exit, 1 for environmental problems (file not 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 found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or invalid
invalid input file, 3 for an internal consistency error (eg, bug) which input file, 3 for an internal consistency error (e.g., bug) which caused
caused minilzip to panic. minilzip to panic.
@node Data format @node Data format
@chapter Data format @chapter Data format
@cindex data format @cindex data format
Perfection is reached, not when there is no longer anything to add, but Perfection is reached, not when there is no longer anything to add, but
when there is no longer anything to take away.@* when there is no longer anything to take away.@*
--- Antoine de Saint-Exupery --- Antoine de Saint-Exupery
@sp 1 @sp 1
skipping to change at line 955 skipping to change at line 953
@verbatim @verbatim
+==============+ +==============+
| | | |
+==============+ +==============+
@end verbatim @end verbatim
represents a variable number of bytes. represents a variable number of bytes.
@sp 1 @sp 1
A lzip data stream consists of a series of "members" (compressed data sets). Lzip data consist of a series of independent "members" (compressed data
The members simply appear one after another in the data stream, with no sets). The members simply appear one after another in the data stream, with
additional information before, between, or after them. 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 data stream is unlimited.
Each member has the following structure: Each member has the following structure:
@verbatim @verbatim
+--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size | | ID string | VN | DS | LZMA stream | CRC32 | Data size | Member size |
+--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +--+--+--+--+----+----+=============+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@end verbatim @end verbatim
All multibyte values are stored in little endian order. All multibyte values are stored in little endian order.
skipping to change at line 988 skipping to change at line 988
@item DS (coded dictionary size, 1 byte) @item DS (coded dictionary size, 1 byte)
The dictionary size is calculated by taking a power of 2 (the base size) 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.@* 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 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 Bits 7-5 contain the numerator of the fraction (0 to 7) to subtract
from the base size to obtain the dictionary size.@* from the base size to obtain the dictionary size.@*
Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@* 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. Valid values for dictionary size range from 4 KiB to 512 MiB.
@item LZMA stream @item LZMA stream
The LZMA stream, finished by an end of stream marker. Uses default values The LZMA stream, finished by an "End Of Stream" marker. Uses default values
for encoder properties. for encoder properties.
@ifnothtml @ifnothtml
@xref{Stream format,,,lzip}, @xref{Stream format,,,lzip},
@end ifnothtml @end ifnothtml
@ifhtml @ifhtml
See See
@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream f ormat} @uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream f ormat}
@end ifhtml @end ifhtml
for a complete description.@* for a complete description.@*
Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib
also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}. also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}.
@item CRC32 (4 bytes) @item CRC32 (4 bytes)
Cyclic Redundancy Check (CRC) of the uncompressed original data. Cyclic Redundancy Check (CRC) of the original uncompressed data.
@item Data size (8 bytes) @item Data size (8 bytes)
Size of the uncompressed original data. Size of the original uncompressed data.
@item Member size (8 bytes) @item Member size (8 bytes)
Total size of the member, including header and trailer. This field acts Total size of the member, including header and trailer. This field acts
as a distributed index, allows the verification of stream integrity, and as a distributed index, allows the verification of stream integrity, and
facilitates safe recovery of undamaged members from multimember files. 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 @end table
@node Examples @node Examples
@chapter A small tutorial with examples @chapter A small tutorial with examples
@cindex examples @cindex examples
This chapter provides real code examples for the most common uses of the This chapter provides real code examples for the most common uses of the
library. See these examples in context in the files @samp{bbexample.c} and library. See these examples in context in the files @samp{bbexample.c} and
@samp{ffexample.c} from the source distribution of lzlib. @samp{ffexample.c} from the source distribution of lzlib.
skipping to change at line 1043 skipping to change at line 1045
@end menu @end menu
@node Buffer compression @node Buffer compression
@section Buffer compression @section Buffer compression
@cindex buffer compression @cindex buffer compression
Buffer-to-buffer single-member compression Buffer-to-buffer single-member compression
@w{(@var{member_size} > total output)}. @w{(@var{member_size} > total output)}.
@verbatim @verbatim
/* Compresses 'insize' bytes from 'inbuf' to 'outbuf'. /* Compress 'insize' bytes from 'inbuf' to 'outbuf'.
Returns the size of the compressed data in '*outlenp'. Return the size of the compressed data in '*outlenp'.
In case of error, or if 'outsize' is too small, returns false and does In case of error, or if 'outsize' is too small, return false and do not
not modify '*outlenp'. modify '*outlenp'.
*/ */
bool bbcompress( const uint8_t * const inbuf, const int insize, bool bbcompress( const uint8_t * const inbuf, const int insize,
const int dictionary_size, const int match_len_limit, const int dictionary_size, const int match_len_limit,
uint8_t * const outbuf, const int outsize, uint8_t * const outbuf, const int outsize,
int * const outlenp ) int * const outlenp )
{ {
int inpos = 0, outpos = 0; int inpos = 0, outpos = 0;
bool error = false; bool error = false;
struct LZ_Encoder * const encoder = struct LZ_Encoder * const encoder =
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX ); LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
skipping to change at line 1087 skipping to change at line 1089
} }
@end verbatim @end verbatim
@node Buffer decompression @node Buffer decompression
@section Buffer decompression @section Buffer decompression
@cindex buffer decompression @cindex buffer decompression
Buffer-to-buffer decompression. Buffer-to-buffer decompression.
@verbatim @verbatim
/* Decompresses 'insize' bytes from 'inbuf' to 'outbuf'. /* Decompress 'insize' bytes from 'inbuf' to 'outbuf'.
Returns the size of the decompressed data in '*outlenp'. Return the size of the decompressed data in '*outlenp'.
In case of error, or if 'outsize' is too small, returns false and does In case of error, or if 'outsize' is too small, return false and do not
not modify '*outlenp'. modify '*outlenp'.
*/ */
bool bbdecompress( const uint8_t * const inbuf, const int insize, bool bbdecompress( const uint8_t * const inbuf, const int insize,
uint8_t * const outbuf, const int outsize, uint8_t * const outbuf, const int outsize,
int * const outlenp ) int * const outlenp )
{ {
int inpos = 0, outpos = 0; int inpos = 0, outpos = 0;
bool error = false; bool error = false;
struct LZ_Decoder * const decoder = LZ_decompress_open(); struct LZ_Decoder * const decoder = LZ_decompress_open();
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ) if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
{ LZ_decompress_close( decoder ); return false; } { LZ_decompress_close( decoder ); return false; }
skipping to change at line 1238 skipping to change at line 1240
return done; return done;
} }
@end verbatim @end verbatim
@sp 1 @sp 1
@noindent @noindent
Example 2: Multimember compression (user-restarted members). Example 2: Multimember compression (user-restarted members).
(Call LZ_compress_open with @var{member_size} > largest member). (Call LZ_compress_open with @var{member_size} > largest member).
@verbatim @verbatim
/* Compresses 'infile' to 'outfile' as a multimember stream with one member /* Compress 'infile' to 'outfile' as a multimember stream with one member
for each line of text terminated by a newline character or by EOF. for each line of text terminated by a newline character or by EOF.
Returns 0 if success, 1 if error. Return 0 if success, 1 if error.
*/ */
int fflfcompress( struct LZ_Encoder * const encoder, int fflfcompress( struct LZ_Encoder * const encoder,
FILE * const infile, FILE * const outfile ) FILE * const infile, FILE * const outfile )
{ {
enum { buffer_size = 16384 }; enum { buffer_size = 16384 };
uint8_t buffer[buffer_size]; uint8_t buffer[buffer_size];
while( true ) while( true )
{ {
int len, ret; int len, ret;
int size = min( buffer_size, LZ_compress_write_size( encoder ) ); int size = min( buffer_size, LZ_compress_write_size( encoder ) );
skipping to change at line 1284 skipping to change at line 1286
} }
return 1; return 1;
} }
@end verbatim @end verbatim
@node Skipping data errors @node Skipping data errors
@section Skipping data errors @section Skipping data errors
@cindex skipping data errors @cindex skipping data errors
@verbatim @verbatim
/* Decompresses 'infile' to 'outfile' with automatic resynchronization to /* Decompress 'infile' to 'outfile' with automatic resynchronization to
next member in case of data error, including the automatic removal of next member in case of data error, including the automatic removal of
leading garbage. leading garbage.
*/ */
int ffrsdecompress( struct LZ_Decoder * const decoder, int ffrsdecompress( struct LZ_Decoder * const decoder,
FILE * const infile, FILE * const outfile ) FILE * const infile, FILE * const outfile )
{ {
enum { buffer_size = 16384 }; enum { buffer_size = 16384 };
uint8_t buffer[buffer_size]; uint8_t buffer[buffer_size];
while( true ) while( true )
{ {
skipping to change at line 1332 skipping to change at line 1334
@cindex bugs @cindex bugs
@cindex getting help @cindex getting help
There are probably bugs in lzlib. There are certainly errors and There are probably bugs in lzlib. There are certainly errors and
omissions in this manual. If you report them, they will get fixed. If omissions in this manual. If you report them, they will get fixed. If
you don't, no one will ever know about them and they will remain unfixed you don't, no one will ever know about them and they will remain unfixed
for all eternity, if not longer. for all eternity, if not longer.
If you find a bug in lzlib, please send electronic mail to If you find a bug in lzlib, please send electronic mail to
@email{lzip-bug@@nongnu.org}. Include the version number, which you can @email{lzip-bug@@nongnu.org}. Include the version number, which you can
find by running @w{@samp{minilzip --version}} or in find by running @w{@samp{minilzip --version}} and
@samp{LZ_version_string} from @samp{lzlib.h}. @w{@samp{minilzip -v --check-lib}}.
@node Concept index @node Concept index
@unnumbered Concept index @unnumbered Concept index
@printindex cp @printindex cp
@bye @bye
 End of changes. 38 change blocks. 
122 lines changed or deleted 124 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)