Compare commits
10 commits
b607405109
...
372d0dafbd
Author | SHA1 | Date | |
---|---|---|---|
372d0dafbd | |||
fd935bd59c | |||
e735d4f439 | |||
996390fa61 | |||
ae3eafc693 | |||
5fdbdd44aa | |||
438f57c427 | |||
8c8d69247f | |||
dcd7b7d39e | |||
1d59584ded |
36 changed files with 996 additions and 968 deletions
|
@ -1,8 +1,7 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
41
ChangeLog
41
ChangeLog
|
@ -1,11 +1,18 @@
|
||||||
2024-04-19 Antonio Diaz Diaz <antonio@gnu.org>
|
2025-01-09 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
* Version 1.15-pre1 released.
|
* Version 1.15 released.
|
||||||
|
* decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte.
|
||||||
|
* minilzip.c (do_decompress): Reject empty member in multimember.
|
||||||
|
(Pp_free): New function.
|
||||||
|
* lzlib.h: Declare LZ_Errno, LZ_Encoder, and LZ_Decoder as typedef.
|
||||||
* Makefile.in: New target 'lib' which builds just the library.
|
* Makefile.in: New target 'lib' which builds just the library.
|
||||||
New target 'bin' which builds the library and minilzip.
|
New target 'bin' which builds the library and minilzip.
|
||||||
'lib' is now the default; minilzip is no longer built by default.
|
'lib' is now the default; minilzip is no longer built by default.
|
||||||
'install-bin' installs minilzip and its man page again.
|
'install-bin' installs minilzip and its man page again.
|
||||||
|
* configure, Makefile.in: Use '--soname' conditionally.
|
||||||
|
(Reported by Michael Sullivan).
|
||||||
* INSTALL: Document use of 'make bin'.
|
* INSTALL: Document use of 'make bin'.
|
||||||
|
* check.sh: Use 'cp' instead of 'cat'.
|
||||||
|
|
||||||
2024-01-20 Antonio Diaz Diaz <antonio@gnu.org>
|
2024-01-20 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
@ -42,8 +49,8 @@
|
||||||
* encoder_base.c (LZeb_try_sync_flush):
|
* encoder_base.c (LZeb_try_sync_flush):
|
||||||
Compensate for the increase in 'rd_min_available_bytes'.
|
Compensate for the increase in 'rd_min_available_bytes'.
|
||||||
* main.c (do_decompress): Fix false report about library stall.
|
* main.c (do_decompress): Fix false report about library stall.
|
||||||
* main.c: New option '--check-lib'.
|
New option '--check-lib'.
|
||||||
* main.c (main): Report an error if a file name is empty.
|
(main): Report an error if a file name is empty.
|
||||||
Make '-o' behave like '-c', but writing to file instead of stdout.
|
Make '-o' behave like '-c', but writing to file instead of stdout.
|
||||||
Make '-c' and '-o' check whether the output is a terminal only once.
|
Make '-c' and '-o' check whether the output is a terminal only once.
|
||||||
Do not open output if input is a terminal.
|
Do not open output if input is a terminal.
|
||||||
|
@ -92,11 +99,11 @@
|
||||||
(Older versions can adjust dictionary size only once).
|
(Older versions can adjust dictionary size only once).
|
||||||
* lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3.
|
* lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3.
|
||||||
* main.c: New option '--loose-trailing'.
|
* main.c: New option '--loose-trailing'.
|
||||||
* main.c (main): Option '-S, --volume-size' now keeps input files.
|
(main): Make option '-S, --volume-size' keep input files.
|
||||||
* main.c: Replace 'bits/byte' with inverse compression ratio.
|
Replace 'bits/byte' with inverse compression ratio in output.
|
||||||
* main.c: Show final diagnostic when testing multiple files.
|
(main): Show final diagnostic when testing multiple files.
|
||||||
* main.c: Do not add a second .lz extension to the arg of -o.
|
(set_c_outname): Do not add a second '.lz' to the arg of '-o'.
|
||||||
* main.c: Show dictionary size at verbosity level 4 (-vvvv).
|
(do_decompress): Show dictionary size at verbosity level 4 (-vvvv).
|
||||||
* lzlib.texi: New chapter 'Invoking minilzip'.
|
* lzlib.texi: New chapter 'Invoking minilzip'.
|
||||||
|
|
||||||
2017-04-11 Antonio Diaz Diaz <antonio@gnu.org>
|
2017-04-11 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
@ -115,12 +122,11 @@
|
||||||
* lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size.
|
* lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size.
|
||||||
* decoder.c (LZd_verify_trailer): Remove test of final code.
|
* decoder.c (LZd_verify_trailer): Remove test of final code.
|
||||||
* main.c: New option '-a, --trailing-error'.
|
* main.c: New option '-a, --trailing-error'.
|
||||||
* main.c (main): Delete '--output' file if infd is a terminal.
|
(main): Delete '--output' file if infd is a terminal.
|
||||||
* main.c (main): Don't use stdin more than once.
|
(main): Don't use stdin more than once.
|
||||||
* configure: Avoid warning on some shells when testing for gcc.
|
* configure: Avoid warning on some shells when testing for gcc.
|
||||||
* Makefile.in: Detect the existence of install-info.
|
* Makefile.in: Detect the existence of install-info.
|
||||||
* check.sh: A POSIX shell is required to run the tests.
|
* check.sh: Require a POSIX shell. Don't check error messages.
|
||||||
* check.sh: Don't check error messages.
|
|
||||||
|
|
||||||
2015-07-08 Antonio Diaz Diaz <antonio@gnu.org>
|
2015-07-08 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
@ -159,8 +165,8 @@
|
||||||
* lzlib.c (LZ_decompress_read): Tell LZ_header_error from
|
* lzlib.c (LZ_decompress_read): Tell LZ_header_error from
|
||||||
LZ_unexpected_eof the same way as lzip does.
|
LZ_unexpected_eof the same way as lzip does.
|
||||||
* Makefile.in: New targets 'install-as-lzip' and 'install-bin'.
|
* Makefile.in: New targets 'install-as-lzip' and 'install-bin'.
|
||||||
* main.c: Use 'setmode' instead of '_setmode' on Windows and OS/2.
|
|
||||||
* main.c: Define 'strtoull' to 'strtoul' on Windows.
|
* main.c: Define 'strtoull' to 'strtoul' on Windows.
|
||||||
|
(main): Use 'setmode' instead of '_setmode' on Windows and OS/2.
|
||||||
|
|
||||||
2012-02-29 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
2012-02-29 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
||||||
|
|
||||||
|
@ -188,9 +194,8 @@
|
||||||
* All declarations not belonging to the API have been
|
* All declarations not belonging to the API have been
|
||||||
encapsulated in the namespace 'Lzlib'.
|
encapsulated in the namespace 'Lzlib'.
|
||||||
* testsuite: Rename 'test1' to 'test.txt'. New tests.
|
* testsuite: Rename 'test1' to 'test.txt'. New tests.
|
||||||
* Match length limits set by options -1 to -9 of minilzip have
|
* main.cc (main): Set match length limits to same values as lzip 1.11.
|
||||||
been changed to match those of lzip 1.11.
|
(main): Set stdin/stdout in binary mode on OS2.
|
||||||
* main.cc: Set stdin/stdout in binary mode on OS2.
|
|
||||||
* bbexample.cc: New file containing example functions for
|
* bbexample.cc: New file containing example functions for
|
||||||
buffer-to-buffer compression/decompression.
|
buffer-to-buffer compression/decompression.
|
||||||
|
|
||||||
|
@ -268,7 +273,7 @@
|
||||||
* Version 0.1 released.
|
* Version 0.1 released.
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is a collection of facts, and thus it is not copyrightable, but just
|
This file is a collection of facts, and thus it is not copyrightable, but just
|
||||||
in case, you have unlimited permission to copy, distribute, and modify it.
|
in case, you have unlimited permission to copy, distribute, and modify it.
|
||||||
|
|
5
INSTALL
5
INSTALL
|
@ -3,7 +3,8 @@ Requirements
|
||||||
You will need a C99 compiler. (gcc 3.3.6 or newer is recommended).
|
You will need a C99 compiler. (gcc 3.3.6 or newer is recommended).
|
||||||
I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards
|
I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards
|
||||||
compliant compiler.
|
compliant compiler.
|
||||||
Gcc is available at http://gcc.gnu.org.
|
Gcc is available at http://gcc.gnu.org
|
||||||
|
Lzip is available at http://www.nongnu.org/lzip/lzip.html
|
||||||
|
|
||||||
The operating system must allow signal handlers read access to objects with
|
The operating system must allow signal handlers read access to objects with
|
||||||
static storage duration so that the cleanup handler for Control-C can delete
|
static storage duration so that the cleanup handler for Control-C can delete
|
||||||
|
@ -85,7 +86,7 @@ After running 'configure', you can run 'make' and 'make install' as
|
||||||
explained above.
|
explained above.
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is free documentation: you have unlimited permission to copy,
|
This file is free documentation: you have unlimited permission to copy,
|
||||||
distribute, and modify it.
|
distribute, and modify it.
|
||||||
|
|
20
Makefile.in
20
Makefile.in
|
@ -2,8 +2,9 @@
|
||||||
DISTNAME = $(pkgname)-$(pkgversion)
|
DISTNAME = $(pkgname)-$(pkgversion)
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
INSTALL_PROGRAM = $(INSTALL) -m 755
|
INSTALL_PROGRAM = $(INSTALL) -m 755
|
||||||
INSTALL_DATA = $(INSTALL) -m 644
|
|
||||||
INSTALL_DIR = $(INSTALL) -d -m 755
|
INSTALL_DIR = $(INSTALL) -d -m 755
|
||||||
|
INSTALL_DATA = $(INSTALL) -m 644
|
||||||
|
INSTALL_SO = $(INSTALL) -m 644
|
||||||
LDCONFIG = /sbin/ldconfig
|
LDCONFIG = /sbin/ldconfig
|
||||||
SHELL = /bin/sh
|
SHELL = /bin/sh
|
||||||
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
|
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
|
||||||
|
@ -27,16 +28,17 @@ lib : $(libname_static) $(libname_shared)
|
||||||
lib$(libname).a : lzlib.o
|
lib$(libname).a : lzlib.o
|
||||||
$(AR) $(ARFLAGS) $@ $<
|
$(AR) $(ARFLAGS) $@ $<
|
||||||
|
|
||||||
lib$(libname).so.$(pkgversion) : lzlib_sh.o
|
lib$(libname).so.$(soversion) : lzlib_sh.o
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $<
|
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=$@ -o $@ $< || \
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $<
|
||||||
|
|
||||||
bin : $(progname_static) $(progname_shared)
|
bin : $(progname_static) $(progname_shared)
|
||||||
|
|
||||||
$(progname) : $(objs) lib$(libname).a
|
$(progname) : $(objs) lib$(libname).a
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).a
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).a
|
||||||
|
|
||||||
$(progname)_shared : $(objs) lib$(libname).so.$(pkgversion)
|
$(progname)_shared : $(objs) lib$(libname).so.$(soversion)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion)
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(soversion)
|
||||||
|
|
||||||
bbexample : bbexample.o lib$(libname).a
|
bbexample : bbexample.o lib$(libname).a
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ bbexample.o lib$(libname).a
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ bbexample.o lib$(libname).a
|
||||||
|
@ -113,13 +115,13 @@ install-lib : lib
|
||||||
$(INSTALL_DATA) ./lib$(libname).a "$(DESTDIR)$(libdir)/lib$(libname).a" ; \
|
$(INSTALL_DATA) ./lib$(libname).a "$(DESTDIR)$(libdir)/lib$(libname).a" ; \
|
||||||
fi
|
fi
|
||||||
if [ -n "$(libname_shared)" ] ; then \
|
if [ -n "$(libname_shared)" ] ; then \
|
||||||
$(INSTALL_PROGRAM) ./lib$(libname).so.$(pkgversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \
|
|
||||||
if [ -e "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ] ; then \
|
if [ -e "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ] ; then \
|
||||||
run_ldconfig=no ; \
|
run_ldconfig=no ; \
|
||||||
else run_ldconfig=yes ; \
|
else run_ldconfig=yes ; \
|
||||||
fi ; \
|
fi ; \
|
||||||
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \
|
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \
|
||||||
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \
|
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \
|
||||||
|
$(INSTALL_SO) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \
|
||||||
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so ; \
|
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so ; \
|
||||||
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so.$(soversion) ; \
|
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so.$(soversion) ; \
|
||||||
if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \
|
if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \
|
||||||
|
@ -127,7 +129,7 @@ install-lib : lib
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install-lib-strip : lib
|
install-lib-strip : lib
|
||||||
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib
|
$(MAKE) INSTALL_SO='$(INSTALL_SO) -s' install-lib
|
||||||
|
|
||||||
install-info :
|
install-info :
|
||||||
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
||||||
|
@ -162,7 +164,6 @@ uninstall-lib :
|
||||||
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).a"
|
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).a"
|
||||||
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so"
|
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so"
|
||||||
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)"
|
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)"
|
||||||
-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)"
|
|
||||||
|
|
||||||
uninstall-info :
|
uninstall-info :
|
||||||
-if $(CAN_RUN_INSTALLINFO) ; then \
|
-if $(CAN_RUN_INSTALLINFO) ; then \
|
||||||
|
@ -196,8 +197,7 @@ dist : doc
|
||||||
$(DISTNAME)/testsuite/fox.lz \
|
$(DISTNAME)/testsuite/fox.lz \
|
||||||
$(DISTNAME)/testsuite/fox_*.lz \
|
$(DISTNAME)/testsuite/fox_*.lz \
|
||||||
$(DISTNAME)/testsuite/test_sync.lz \
|
$(DISTNAME)/testsuite/test_sync.lz \
|
||||||
$(DISTNAME)/testsuite/test.txt.lz \
|
$(DISTNAME)/testsuite/test.txt.lz
|
||||||
$(DISTNAME)/testsuite/test_em.txt.lz
|
|
||||||
rm -f $(DISTNAME)
|
rm -f $(DISTNAME)
|
||||||
lzip -v -9 $(DISTNAME).tar
|
lzip -v -9 $(DISTNAME).tar
|
||||||
|
|
||||||
|
|
10
NEWS
10
NEWS
|
@ -1,5 +1,12 @@
|
||||||
Changes in version 1.15:
|
Changes in version 1.15:
|
||||||
|
|
||||||
|
Lzlib now reports a nonzero first LZMA byte as a LZ_data_error.
|
||||||
|
|
||||||
|
minilzip now exits with error status 2 if any empty member is found in a
|
||||||
|
multimember file.
|
||||||
|
|
||||||
|
LZ_Errno, LZ_Encoder, and LZ_Decoder are now declared in lzlib.h as typedef.
|
||||||
|
|
||||||
The targets 'lib' and 'bin' have been added to Makefile.in. 'lib' is the new
|
The targets 'lib' and 'bin' have been added to Makefile.in. 'lib' is the new
|
||||||
default and builds just the library. 'bin' builds both the library and
|
default and builds just the library. 'bin' builds both the library and
|
||||||
minilzip.
|
minilzip.
|
||||||
|
@ -8,4 +15,7 @@ minilzip is no longer built by default.
|
||||||
|
|
||||||
'install-bin' installs minilzip and its man page again.
|
'install-bin' installs minilzip and its man page again.
|
||||||
|
|
||||||
|
To improve portability, the linker option '--soname' is now used conditionally.
|
||||||
|
(Reported by Michael Sullivan).
|
||||||
|
|
||||||
The use of the target 'bin' has been documented in INSTALL.
|
The use of the target 'bin' has been documented in INSTALL.
|
||||||
|
|
43
README
43
README
|
@ -1,40 +1,18 @@
|
||||||
|
See the file INSTALL for compilation and installation instructions.
|
||||||
|
|
||||||
Description
|
Description
|
||||||
|
|
||||||
Lzlib is a data compression library providing in-memory LZMA compression and
|
Lzlib is a data compression library providing in-memory LZMA compression and
|
||||||
decompression functions, including integrity checking of the decompressed
|
decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the lzip format.
|
||||||
Lzlib is written in C.
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
|
|
||||||
The lzip file format is designed for data sharing and long-term archiving,
|
|
||||||
taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
* The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program lziprecover can repair bit flip errors
|
|
||||||
(one of the most common forms of data corruption) in lzip files, and
|
|
||||||
provides data recovery capabilities, including error-checked merging
|
|
||||||
of damaged copies of a file.
|
|
||||||
|
|
||||||
* 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
|
|
||||||
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
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
* Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
|
|
||||||
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
|
|
||||||
lziprecover, losing an entire archive just because of a corrupt byte near
|
|
||||||
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 'lzlib.h'. Usage examples of the library are given
|
are declared in the file 'lzlib.h'. Usage examples of the library are given
|
||||||
in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source
|
in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source
|
||||||
distribution.
|
distribution.
|
||||||
|
|
||||||
As 'lzlib.h' can be used by C and C++ programs, it must not impose a choice
|
As 'lzlib.h' can be used in C and C++ programs, it must not impose a choice
|
||||||
of system headers on the program by including one of them. Therefore it is
|
of system headers on the program by including one of them. Therefore it is
|
||||||
the responsibility of the program using lzlib to include before 'lzlib.h'
|
the responsibility of the program using lzlib to include before 'lzlib.h'
|
||||||
some header that declares the type 'uint8_t'. There are at least four such
|
some header that declares the type 'uint8_t'. There are at least four such
|
||||||
|
@ -74,10 +52,10 @@ 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 '-0' of lzip uses the scheme in almost the
|
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
||||||
simplest way possible; issuing the longest match it can find, or a literal
|
simplest way possible; issuing the longest match it can find, or a literal
|
||||||
byte if it can't find a match. Inversely, a much more elaborated way of
|
byte if it can't find a match. Inversely, a more elaborate way of finding
|
||||||
finding coding sequences of minimum size than the one currently used by lzip
|
coding sequences of minimum size than the one currently used by lzip could
|
||||||
could be developed, and the resulting sequence could also be coded using the
|
be developed, and the resulting sequence could also be coded using the LZMA
|
||||||
LZMA coding scheme.
|
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 '-0' of minilzip) and normal (used by all other compression levels).
|
option '-0' of minilzip) and normal (used by all other compression levels).
|
||||||
|
@ -98,8 +76,11 @@ LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never have
|
||||||
been compressed. Decompressed is used to refer to data which have undergone
|
been compressed. Decompressed is used to refer to data which have undergone
|
||||||
the process of decompression.
|
the process of decompression.
|
||||||
|
|
||||||
|
minilzip uses Arg_parser for command-line argument parsing:
|
||||||
|
http://www.nongnu.org/arg-parser/arg_parser.html
|
||||||
|
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
|
||||||
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is free documentation: you have unlimited permission to copy,
|
This file is free documentation: you have unlimited permission to copy,
|
||||||
distribute, and modify it.
|
distribute, and modify it.
|
||||||
|
|
22
bbexample.c
22
bbexample.c
|
@ -1,5 +1,5 @@
|
||||||
/* Buffer to buffer example - Test program for the library lzlib
|
/* Buffer to buffer example - Test program for the library lzlib
|
||||||
Copyright (C) 2010-2024 Antonio Diaz Diaz.
|
Copyright (C) 2010-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This program is free software: you have unlimited permission
|
This program is free software: you have unlimited permission
|
||||||
to copy, distribute, and modify it.
|
to copy, distribute, and modify it.
|
||||||
|
@ -81,14 +81,14 @@ uint8_t * read_file( const char * const name, long * const file_sizep )
|
||||||
uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
const int level, long * const outlenp )
|
const int level, long * const outlenp )
|
||||||
{
|
{
|
||||||
struct Lzma_options
|
typedef struct Lzma_options
|
||||||
{
|
{
|
||||||
int dictionary_size; /* 4 KiB .. 512 MiB */
|
int dictionary_size; /* 4 KiB .. 512 MiB */
|
||||||
int match_len_limit; /* 5 .. 273 */
|
int match_len_limit; /* 5 .. 273 */
|
||||||
};
|
} Lzma_options;
|
||||||
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
||||||
corresponding LZMA compression parameters. */
|
corresponding LZMA compression parameters. */
|
||||||
const struct Lzma_options option_mapping[] =
|
const Lzma_options option_mapping[] =
|
||||||
{
|
{
|
||||||
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
||||||
{ 1 << 20, 5 }, /* -1 */
|
{ 1 << 20, 5 }, /* -1 */
|
||||||
|
@ -100,10 +100,10 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
{ 1 << 24, 68 }, /* -7 */
|
{ 1 << 24, 68 }, /* -7 */
|
||||||
{ 3 << 23, 132 }, /* -8 */
|
{ 3 << 23, 132 }, /* -8 */
|
||||||
{ 1 << 25, 273 } }; /* -9 */
|
{ 1 << 25, 273 } }; /* -9 */
|
||||||
struct Lzma_options encoder_options;
|
Lzma_options encoder_options;
|
||||||
struct LZ_Encoder * encoder;
|
LZ_Encoder * encoder;
|
||||||
uint8_t * outbuf;
|
uint8_t * outbuf;
|
||||||
const long delta_size = ( insize / 4 ) + 64; /* insize may be zero */
|
const long delta_size = insize / 4 + 64; /* insize may be zero */
|
||||||
long outsize = delta_size; /* initial outsize */
|
long outsize = delta_size; /* initial outsize */
|
||||||
long inpos = 0;
|
long inpos = 0;
|
||||||
long outpos = 0;
|
long outpos = 0;
|
||||||
|
@ -160,7 +160,7 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize,
|
uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize,
|
||||||
long * const outlenp )
|
long * const outlenp )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
const long delta_size = insize; /* insize must be > zero */
|
const long delta_size = insize; /* insize must be > zero */
|
||||||
long outsize = delta_size; /* initial outsize */
|
long outsize = delta_size; /* initial outsize */
|
||||||
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
||||||
|
@ -242,7 +242,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -278,7 +278,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
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; }
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
int retval = 0, i;
|
int retval = 0, i;
|
||||||
int open_failures = 0;
|
int open_failures = 0;
|
||||||
const bool verbose = ( argc > 2 );
|
const bool verbose = argc > 2;
|
||||||
|
|
||||||
if( argc < 2 )
|
if( argc < 2 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
|
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
|
||||||
Copyright (C) 2006-2024 Antonio Diaz Diaz.
|
Copyright (C) 2006-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -32,15 +32,15 @@ static void * ap_resize_buffer( void * buf, const int min_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char push_back_record( struct Arg_parser * const ap, const int code,
|
static char push_back_record( Arg_parser * const ap, const int code,
|
||||||
const char * const long_name,
|
const char * const long_name,
|
||||||
const char * const argument )
|
const char * const argument )
|
||||||
{
|
{
|
||||||
struct ap_Record * p;
|
ap_Record * p;
|
||||||
void * tmp = ap_resize_buffer( ap->data,
|
void * tmp = ap_resize_buffer( ap->data,
|
||||||
( ap->data_size + 1 ) * sizeof (struct ap_Record) );
|
( ap->data_size + 1 ) * sizeof (ap_Record) );
|
||||||
if( !tmp ) return 0;
|
if( !tmp ) return 0;
|
||||||
ap->data = (struct ap_Record *)tmp;
|
ap->data = (ap_Record *)tmp;
|
||||||
p = &(ap->data[ap->data_size]);
|
p = &(ap->data[ap->data_size]);
|
||||||
p->code = code;
|
p->code = code;
|
||||||
if( long_name )
|
if( long_name )
|
||||||
|
@ -71,7 +71,7 @@ static char push_back_record( struct Arg_parser * const ap, const int code,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char add_error( struct Arg_parser * const ap, const char * const msg )
|
static char add_error( Arg_parser * const ap, const char * const msg )
|
||||||
{
|
{
|
||||||
const int len = strlen( msg );
|
const int len = strlen( msg );
|
||||||
void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 );
|
void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 );
|
||||||
|
@ -83,7 +83,7 @@ static char add_error( struct Arg_parser * const ap, const char * const msg )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void free_data( struct Arg_parser * const ap )
|
static void free_data( Arg_parser * const ap )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < ap->data_size; ++i )
|
for( i = 0; i < ap->data_size; ++i )
|
||||||
|
@ -94,10 +94,9 @@ static void free_data( struct Arg_parser * const ap )
|
||||||
|
|
||||||
|
|
||||||
/* Return 0 only if out of memory. */
|
/* Return 0 only if out of memory. */
|
||||||
static char parse_long_option( struct Arg_parser * const ap,
|
static char parse_long_option( Arg_parser * const ap,
|
||||||
const char * const opt, const char * const arg,
|
const char * const opt, const char * const arg,
|
||||||
const struct ap_Option options[],
|
const ap_Option options[], int * const argindp )
|
||||||
int * const argindp )
|
|
||||||
{
|
{
|
||||||
unsigned len;
|
unsigned len;
|
||||||
int index = -1, i;
|
int index = -1, i;
|
||||||
|
@ -148,21 +147,21 @@ static char parse_long_option( struct Arg_parser * const ap,
|
||||||
add_error( ap, "' requires an argument" );
|
add_error( ap, "' requires an argument" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return push_back_record( ap, options[index].code,
|
return push_back_record( ap, options[index].code, options[index].long_name,
|
||||||
options[index].long_name, &opt[len+3] );
|
&opt[len+3] ); /* argument may be empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
if( options[index].has_arg == ap_yes )
|
if( options[index].has_arg == ap_yes || options[index].has_arg == ap_yme )
|
||||||
{
|
{
|
||||||
if( !arg || !arg[0] )
|
if( !arg || ( options[index].has_arg == ap_yes && !arg[0] ) )
|
||||||
{
|
{
|
||||||
add_error( ap, "option '--" ); add_error( ap, options[index].long_name );
|
add_error( ap, "option '--" ); add_error( ap, options[index].long_name );
|
||||||
add_error( ap, "' requires an argument" );
|
add_error( ap, "' requires an argument" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
++*argindp;
|
++*argindp;
|
||||||
return push_back_record( ap, options[index].code,
|
return push_back_record( ap, options[index].code, options[index].long_name,
|
||||||
options[index].long_name, arg );
|
arg ); /* argument may be empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
return push_back_record( ap, options[index].code,
|
return push_back_record( ap, options[index].code,
|
||||||
|
@ -171,10 +170,9 @@ static char parse_long_option( struct Arg_parser * const ap,
|
||||||
|
|
||||||
|
|
||||||
/* Return 0 only if out of memory. */
|
/* Return 0 only if out of memory. */
|
||||||
static char parse_short_option( struct Arg_parser * const ap,
|
static char parse_short_option( Arg_parser * const ap,
|
||||||
const char * const opt, const char * const arg,
|
const char * const opt, const char * const arg,
|
||||||
const struct ap_Option options[],
|
const ap_Option options[], int * const argindp )
|
||||||
int * const argindp )
|
|
||||||
{
|
{
|
||||||
int cind = 1; /* character index in opt */
|
int cind = 1; /* character index in opt */
|
||||||
|
|
||||||
|
@ -204,15 +202,15 @@ static char parse_short_option( struct Arg_parser * const ap,
|
||||||
if( !push_back_record( ap, c, 0, &opt[cind] ) ) return 0;
|
if( !push_back_record( ap, c, 0, &opt[cind] ) ) return 0;
|
||||||
++*argindp; cind = 0;
|
++*argindp; cind = 0;
|
||||||
}
|
}
|
||||||
else if( options[index].has_arg == ap_yes )
|
else if( options[index].has_arg == ap_yes || options[index].has_arg == ap_yme )
|
||||||
{
|
{
|
||||||
if( !arg || !arg[0] )
|
if( !arg || ( options[index].has_arg == ap_yes && !arg[0] ) )
|
||||||
{
|
{
|
||||||
add_error( ap, "option requires an argument -- '" );
|
add_error( ap, "option requires an argument -- '" );
|
||||||
add_error( ap, code_str ); add_error( ap, "'" );
|
add_error( ap, code_str ); add_error( ap, "'" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
++*argindp; cind = 0;
|
++*argindp; cind = 0; /* argument may be empty */
|
||||||
if( !push_back_record( ap, c, 0, arg ) ) return 0;
|
if( !push_back_record( ap, c, 0, arg ) ) return 0;
|
||||||
}
|
}
|
||||||
else if( !push_back_record( ap, c, 0, 0 ) ) return 0;
|
else if( !push_back_record( ap, c, 0, 0 ) ) return 0;
|
||||||
|
@ -221,9 +219,9 @@ static char parse_short_option( struct Arg_parser * const ap,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char ap_init( struct Arg_parser * const ap,
|
char ap_init( Arg_parser * const ap,
|
||||||
const int argc, const char * const argv[],
|
const int argc, const char * const argv[],
|
||||||
const struct ap_Option options[], const char in_order )
|
const ap_Option options[], const char in_order )
|
||||||
{
|
{
|
||||||
const char ** non_options = 0; /* skipped non-options */
|
const char ** non_options = 0; /* skipped non-options */
|
||||||
int non_options_size = 0; /* number of skipped non-options */
|
int non_options_size = 0; /* number of skipped non-options */
|
||||||
|
@ -282,7 +280,7 @@ out: if( non_options ) free( non_options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ap_free( struct Arg_parser * const ap )
|
void ap_free( Arg_parser * const ap )
|
||||||
{
|
{
|
||||||
free_data( ap );
|
free_data( ap );
|
||||||
if( ap->error ) { free( ap->error ); ap->error = 0; }
|
if( ap->error ) { free( ap->error ); ap->error = 0; }
|
||||||
|
@ -290,29 +288,25 @@ void ap_free( struct Arg_parser * const ap )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_error( const struct Arg_parser * const ap )
|
const char * ap_error( const Arg_parser * const ap ) { return ap->error; }
|
||||||
{ return ap->error; }
|
|
||||||
|
|
||||||
|
int ap_arguments( const Arg_parser * const ap ) { return ap->data_size; }
|
||||||
|
|
||||||
int ap_arguments( const struct Arg_parser * const ap )
|
int ap_code( const Arg_parser * const ap, const int i )
|
||||||
{ return ap->data_size; }
|
|
||||||
|
|
||||||
|
|
||||||
int ap_code( const struct Arg_parser * const ap, const int i )
|
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) ) return 0;
|
if( i < 0 || i >= ap_arguments( ap ) ) return 0;
|
||||||
return ap->data[i].code;
|
return ap->data[i].code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i )
|
const char * ap_parsed_name( const Arg_parser * const ap, const int i )
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return "";
|
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return "";
|
||||||
return ap->data[i].parsed_name;
|
return ap->data[i].parsed_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_argument( const struct Arg_parser * const ap, const int i )
|
const char * ap_argument( const Arg_parser * const ap, const int i )
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return "";
|
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return "";
|
||||||
return ap->data[i].argument;
|
return ap->data[i].argument;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
|
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
|
||||||
Copyright (C) 2006-2024 Antonio Diaz Diaz.
|
Copyright (C) 2006-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -37,60 +37,65 @@
|
||||||
The argument '--' terminates all options; any following arguments are
|
The argument '--' terminates all options; any following arguments are
|
||||||
treated as non-option arguments, even if they begin with a hyphen.
|
treated as non-option arguments, even if they begin with a hyphen.
|
||||||
|
|
||||||
The syntax for optional option arguments is '-<short_option><argument>'
|
The syntax of options with an optional argument is
|
||||||
(without whitespace), or '--<long_option>=<argument>'.
|
'-<short_option><argument>' (without whitespace), or
|
||||||
|
'--<long_option>=<argument>'.
|
||||||
|
|
||||||
|
The syntax of options with an empty argument is '-<short_option> ""',
|
||||||
|
'--<long_option> ""', or '--<long_option>=""'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum ap_Has_arg { ap_no, ap_yes, ap_maybe };
|
/* ap_yme = yes but maybe empty */
|
||||||
|
typedef enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme } ap_Has_arg;
|
||||||
|
|
||||||
struct ap_Option
|
typedef struct ap_Option
|
||||||
{
|
{
|
||||||
int code; /* Short option letter or code ( code != 0 ) */
|
int code; /* Short option letter or code ( code != 0 ) */
|
||||||
const char * long_name; /* Long option name (maybe null) */
|
const char * long_name; /* Long option name (maybe null) */
|
||||||
enum ap_Has_arg has_arg;
|
ap_Has_arg has_arg;
|
||||||
};
|
} ap_Option;
|
||||||
|
|
||||||
|
|
||||||
struct ap_Record
|
typedef struct ap_Record
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
char * parsed_name;
|
char * parsed_name;
|
||||||
char * argument;
|
char * argument;
|
||||||
};
|
} ap_Record;
|
||||||
|
|
||||||
|
|
||||||
struct Arg_parser
|
typedef struct Arg_parser
|
||||||
{
|
{
|
||||||
struct ap_Record * data;
|
ap_Record * data;
|
||||||
char * error;
|
char * error;
|
||||||
int data_size;
|
int data_size;
|
||||||
int error_size;
|
int error_size;
|
||||||
};
|
} Arg_parser;
|
||||||
|
|
||||||
|
|
||||||
char ap_init( struct Arg_parser * const ap,
|
char ap_init( Arg_parser * const ap,
|
||||||
const int argc, const char * const argv[],
|
const int argc, const char * const argv[],
|
||||||
const struct ap_Option options[], const char in_order );
|
const ap_Option options[], const char in_order );
|
||||||
|
|
||||||
void ap_free( struct Arg_parser * const ap );
|
void ap_free( Arg_parser * const ap );
|
||||||
|
|
||||||
const char * ap_error( const struct Arg_parser * const ap );
|
const char * ap_error( const Arg_parser * const ap );
|
||||||
|
|
||||||
/* The number of arguments parsed. May be different from argc. */
|
/* The number of arguments parsed. May be different from argc. */
|
||||||
int ap_arguments( const struct Arg_parser * const ap );
|
int ap_arguments( const Arg_parser * const ap );
|
||||||
|
|
||||||
/* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
|
/* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
|
||||||
Else ap_argument( i ) is the option's argument (or empty). */
|
Else ap_argument( i ) is the option's argument (or empty). */
|
||||||
int ap_code( const struct Arg_parser * const ap, const int i );
|
int ap_code( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
/* Full name of the option parsed (short or long). */
|
/* Full name of the option parsed (short or long). */
|
||||||
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i );
|
const char * ap_parsed_name( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
const char * ap_argument( const struct Arg_parser * const ap, const int i );
|
const char * ap_argument( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
30
cbuffer.c
30
cbuffer.c
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,15 +17,15 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Circular_buffer
|
typedef struct Circular_buffer
|
||||||
{
|
{
|
||||||
uint8_t * buffer;
|
uint8_t * buffer;
|
||||||
unsigned buffer_size; /* capacity == buffer_size - 1 */
|
unsigned buffer_size; /* capacity == buffer_size - 1 */
|
||||||
unsigned get; /* buffer is empty when get == put */
|
unsigned get; /* buffer is empty when get == put */
|
||||||
unsigned put;
|
unsigned put;
|
||||||
};
|
} Circular_buffer;
|
||||||
|
|
||||||
static inline bool Cb_init( struct Circular_buffer * const cb,
|
static inline bool Cb_init( Circular_buffer * const cb,
|
||||||
const unsigned buf_size )
|
const unsigned buf_size )
|
||||||
{
|
{
|
||||||
cb->buffer_size = buf_size + 1;
|
cb->buffer_size = buf_size + 1;
|
||||||
|
@ -36,38 +36,36 @@ static inline bool Cb_init( struct Circular_buffer * const cb,
|
||||||
return cb->buffer != 0;
|
return cb->buffer != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Cb_free( struct Circular_buffer * const cb )
|
static inline void Cb_free( Circular_buffer * const cb )
|
||||||
{ free( cb->buffer ); cb->buffer = 0; }
|
{ free( cb->buffer ); cb->buffer = 0; }
|
||||||
|
|
||||||
static inline void Cb_reset( struct Circular_buffer * const cb )
|
static inline void Cb_reset( Circular_buffer * const cb )
|
||||||
{ cb->get = 0; cb->put = 0; }
|
{ cb->get = 0; cb->put = 0; }
|
||||||
|
|
||||||
static inline unsigned Cb_empty( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_empty( const Circular_buffer * const cb )
|
||||||
{ return cb->get == cb->put; }
|
{ return cb->get == cb->put; }
|
||||||
|
|
||||||
static inline unsigned Cb_used_bytes( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_used_bytes( const Circular_buffer * const cb )
|
||||||
{ return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; }
|
{ return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; }
|
||||||
|
|
||||||
static inline unsigned Cb_free_bytes( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_free_bytes( const Circular_buffer * const cb )
|
||||||
{ return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; }
|
{ return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; }
|
||||||
|
|
||||||
static inline uint8_t Cb_get_byte( struct Circular_buffer * const cb )
|
static inline uint8_t Cb_get_byte( Circular_buffer * const cb )
|
||||||
{
|
{
|
||||||
const uint8_t b = cb->buffer[cb->get];
|
const uint8_t b = cb->buffer[cb->get];
|
||||||
if( ++cb->get >= cb->buffer_size ) cb->get = 0;
|
if( ++cb->get >= cb->buffer_size ) cb->get = 0;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Cb_put_byte( struct Circular_buffer * const cb,
|
static inline void Cb_put_byte( Circular_buffer * const cb, const uint8_t b )
|
||||||
const uint8_t b )
|
|
||||||
{
|
{
|
||||||
cb->buffer[cb->put] = b;
|
cb->buffer[cb->put] = b;
|
||||||
if( ++cb->put >= cb->buffer_size ) cb->put = 0;
|
if( ++cb->put >= cb->buffer_size ) cb->put = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool Cb_unread_data( struct Circular_buffer * const cb,
|
static bool Cb_unread_data( Circular_buffer * const cb, const unsigned size )
|
||||||
const unsigned size )
|
|
||||||
{
|
{
|
||||||
if( size > Cb_free_bytes( cb ) ) return false;
|
if( size > Cb_free_bytes( cb ) ) return false;
|
||||||
if( cb->get >= size ) cb->get -= size;
|
if( cb->get >= size ) cb->get -= size;
|
||||||
|
@ -80,7 +78,7 @@ static bool Cb_unread_data( struct Circular_buffer * const cb,
|
||||||
If 'out_buffer' is null, the bytes are discarded.
|
If 'out_buffer' is null, the bytes are discarded.
|
||||||
Return the number of bytes copied or discarded.
|
Return the number of bytes copied or discarded.
|
||||||
*/
|
*/
|
||||||
static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
static unsigned Cb_read_data( Circular_buffer * const cb,
|
||||||
uint8_t * const out_buffer,
|
uint8_t * const out_buffer,
|
||||||
const unsigned out_size )
|
const unsigned out_size )
|
||||||
{
|
{
|
||||||
|
@ -113,7 +111,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
||||||
/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'.
|
/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'.
|
||||||
Return the number of bytes copied.
|
Return the number of bytes copied.
|
||||||
*/
|
*/
|
||||||
static unsigned Cb_write_data( struct Circular_buffer * const cb,
|
static unsigned Cb_write_data( Circular_buffer * const cb,
|
||||||
const uint8_t * const in_buffer,
|
const uint8_t * const in_buffer,
|
||||||
const unsigned in_size )
|
const unsigned in_size )
|
||||||
{
|
{
|
||||||
|
|
12
configure
vendored
12
configure
vendored
|
@ -1,12 +1,12 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# configure script for Lzlib - Compression library for the lzip format
|
# configure script for Lzlib - Compression library for the lzip format
|
||||||
# Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
# Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
#
|
#
|
||||||
# This configure script is free software: you have unlimited permission
|
# This configure script is free software: you have unlimited permission
|
||||||
# to copy, distribute, and modify it.
|
# to copy, distribute, and modify it.
|
||||||
|
|
||||||
pkgname=lzlib
|
pkgname=lzlib
|
||||||
pkgversion=1.15-pre1
|
pkgversion=1.15
|
||||||
soversion=1
|
soversion=1
|
||||||
libname=lz
|
libname=lz
|
||||||
libname_static=lib${libname}.a
|
libname_static=lib${libname}.a
|
||||||
|
@ -118,12 +118,12 @@ while [ $# != 0 ] ; do
|
||||||
--no-create) no_create=yes ;;
|
--no-create) no_create=yes ;;
|
||||||
--disable-static)
|
--disable-static)
|
||||||
libname_static=
|
libname_static=
|
||||||
libname_shared=lib${libname}.so.${pkgversion}
|
|
||||||
progname_static=
|
progname_static=
|
||||||
|
libname_shared=lib${libname}.so.${soversion}
|
||||||
progname_shared=${progname}_shared
|
progname_shared=${progname}_shared
|
||||||
progname_lzip=${progname}_shared ;;
|
progname_lzip=${progname}_shared ;;
|
||||||
--enable-shared)
|
--enable-shared)
|
||||||
libname_shared=lib${libname}.so.${pkgversion}
|
libname_shared=lib${libname}.so.${soversion}
|
||||||
progname_shared=${progname}_shared
|
progname_shared=${progname}_shared
|
||||||
progname_lzip=${progname}_shared ;;
|
progname_lzip=${progname}_shared ;;
|
||||||
--disable-ldconfig) disable_ldconfig=yes ;;
|
--disable-ldconfig) disable_ldconfig=yes ;;
|
||||||
|
@ -146,7 +146,7 @@ while [ $# != 0 ] ; do
|
||||||
exit 1 ;;
|
exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check if the option took a separate argument
|
# Check whether the option took a separate argument
|
||||||
if [ "${arg2}" = yes ] ; then
|
if [ "${arg2}" = yes ] ; then
|
||||||
if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift
|
if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift
|
||||||
else echo "configure: Missing argument to '${option}'" 1>&2
|
else echo "configure: Missing argument to '${option}'" 1>&2
|
||||||
|
@ -212,7 +212,7 @@ echo "MAKEINFO = ${MAKEINFO}"
|
||||||
rm -f Makefile
|
rm -f Makefile
|
||||||
cat > Makefile << EOF
|
cat > Makefile << EOF
|
||||||
# Makefile for Lzlib - Compression library for the lzip format
|
# Makefile for Lzlib - Compression library for the lzip format
|
||||||
# Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
# Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
# This file was generated automatically by configure. Don't edit.
|
# This file was generated automatically by configure. Don't edit.
|
||||||
#
|
#
|
||||||
# This Makefile is free software: you have unlimited permission
|
# This Makefile is free software: you have unlimited permission
|
||||||
|
|
32
debian/changelog
vendored
32
debian/changelog
vendored
|
@ -1,3 +1,35 @@
|
||||||
|
lzlib (1.15-1) sid; urgency=medium
|
||||||
|
|
||||||
|
* Uploading to sid.
|
||||||
|
* Merging upstream version 1.15.
|
||||||
|
|
||||||
|
-- Daniel Baumann <daniel.baumann@progress-linux.org> Wed, 15 Jan 2025 05:08:29 +0100
|
||||||
|
|
||||||
|
lzlib (1.15~rc1-1) sid; urgency=medium
|
||||||
|
|
||||||
|
* Uploading to sid.
|
||||||
|
* Merging upstream version 1.15~rc1.
|
||||||
|
* Removing soname.patch, not required anymore.
|
||||||
|
|
||||||
|
-- Daniel Baumann <daniel.baumann@progress-linux.org> Wed, 27 Nov 2024 22:27:00 +0100
|
||||||
|
|
||||||
|
lzlib (1.15~pre2-1) sid; urgency=medium
|
||||||
|
|
||||||
|
* Uploading to sid.
|
||||||
|
* Merging upstream version 1.15~pre2.
|
||||||
|
* Adding patch to revert removal of --soname to fix FTBFS.
|
||||||
|
|
||||||
|
-- Daniel Baumann <daniel.baumann@progress-linux.org> Tue, 22 Oct 2024 18:38:44 +0200
|
||||||
|
|
||||||
|
lzlib (1.15~pre1-1) sid; urgency=medium
|
||||||
|
|
||||||
|
* Uploading to sid.
|
||||||
|
* Updating to standards-version 4.7.0.
|
||||||
|
* Merging upstream version 1.15~pre1.
|
||||||
|
* Updating rules to adjust for not building minilzip by default anymore.
|
||||||
|
|
||||||
|
-- Daniel Baumann <daniel.baumann@progress-linux.org> Sat, 27 Apr 2024 04:41:16 +0200
|
||||||
|
|
||||||
lzlib (1.14-1) sid; urgency=medium
|
lzlib (1.14-1) sid; urgency=medium
|
||||||
|
|
||||||
* Uploading to sid.
|
* Uploading to sid.
|
||||||
|
|
3
debian/rules
vendored
3
debian/rules
vendored
|
@ -12,6 +12,9 @@ endif
|
||||||
override_dh_auto_configure:
|
override_dh_auto_configure:
|
||||||
dh_auto_configure -- --enable-shared --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) 'CC=$(CC)'
|
dh_auto_configure -- --enable-shared --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) 'CC=$(CC)'
|
||||||
|
|
||||||
|
override_dh_auto_build:
|
||||||
|
dh_auto_build -- bin
|
||||||
|
|
||||||
override_dh_auto_install:
|
override_dh_auto_install:
|
||||||
dh_auto_install -- LDCONFIG=/bin/true
|
dh_auto_install -- LDCONFIG=/bin/true
|
||||||
|
|
||||||
|
|
25
decoder.c
25
decoder.c
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int LZd_try_check_trailer( struct LZ_decoder * const d )
|
static int LZd_try_check_trailer( LZ_decoder * const d )
|
||||||
{
|
{
|
||||||
Lzip_trailer trailer;
|
Lzip_trailer trailer;
|
||||||
if( Rd_available_bytes( d->rdec ) < Lt_size )
|
if( Rd_available_bytes( d->rdec ) < Lt_size )
|
||||||
|
@ -35,22 +35,23 @@ static int LZd_try_check_trailer( struct LZ_decoder * const d )
|
||||||
|
|
||||||
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
|
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
|
||||||
3 = trailer error, 4 = unknown marker found,
|
3 = trailer error, 4 = unknown marker found,
|
||||||
5 = library error. */
|
5 = nonzero first LZMA byte found, 6 = library error. */
|
||||||
static int LZd_decode_member( struct LZ_decoder * const d )
|
static int LZd_decode_member( LZ_decoder * const d )
|
||||||
{
|
{
|
||||||
struct Range_decoder * const rdec = d->rdec;
|
Range_decoder * const rdec = d->rdec;
|
||||||
State * const state = &d->state;
|
State * const state = &d->state;
|
||||||
unsigned old_mpos = rdec->member_position;
|
unsigned old_mpos = rdec->member_position;
|
||||||
|
|
||||||
if( d->member_finished ) return 0;
|
if( d->member_finished ) return 0;
|
||||||
if( !Rd_try_reload( rdec ) )
|
const int tmp = Rd_try_reload( rdec );
|
||||||
{ if( !rdec->at_stream_end ) return 0; else return 2; }
|
if( tmp > 1 ) return 5;
|
||||||
|
if( !tmp ) { if( !rdec->at_stream_end ) return 0; else return 2; }
|
||||||
if( d->check_trailer_pending ) return LZd_try_check_trailer( d );
|
if( d->check_trailer_pending ) return LZd_try_check_trailer( d );
|
||||||
|
|
||||||
while( !Rd_finished( rdec ) )
|
while( !Rd_finished( rdec ) )
|
||||||
{
|
{
|
||||||
const unsigned mpos = rdec->member_position;
|
const unsigned mpos = rdec->member_position;
|
||||||
if( mpos - old_mpos > rd_min_available_bytes ) return 5;
|
if( mpos - old_mpos > rd_min_available_bytes ) return 6;
|
||||||
old_mpos = mpos;
|
old_mpos = mpos;
|
||||||
if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */
|
if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */
|
||||||
{ if( !rdec->at_stream_end ) return 0;
|
{ if( !rdec->at_stream_end ) return 0;
|
||||||
|
@ -74,7 +75,7 @@ static int LZd_decode_member( struct LZ_decoder * const d )
|
||||||
if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */
|
if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */
|
||||||
{
|
{
|
||||||
if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */
|
if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */
|
||||||
{ *state = St_set_short_rep( *state );
|
{ *state = St_set_shortrep( *state );
|
||||||
LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; }
|
LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -117,7 +118,7 @@ static int LZd_decode_member( struct LZ_decoder * const d )
|
||||||
{
|
{
|
||||||
Rd_normalize( rdec );
|
Rd_normalize( rdec );
|
||||||
const unsigned mpos = rdec->member_position;
|
const unsigned mpos = rdec->member_position;
|
||||||
if( mpos - old_mpos > rd_min_available_bytes ) return 5;
|
if( mpos - old_mpos > rd_min_available_bytes ) return 6;
|
||||||
old_mpos = mpos;
|
old_mpos = mpos;
|
||||||
if( len == min_match_len ) /* End Of Stream marker */
|
if( len == min_match_len ) /* End Of Stream marker */
|
||||||
{
|
{
|
||||||
|
@ -127,7 +128,9 @@ static int LZd_decode_member( struct LZ_decoder * const d )
|
||||||
if( len == min_match_len + 1 ) /* Sync Flush marker */
|
if( len == min_match_len + 1 ) /* Sync Flush marker */
|
||||||
{
|
{
|
||||||
rdec->reload_pending = true;
|
rdec->reload_pending = true;
|
||||||
if( Rd_try_reload( rdec ) ) continue;
|
const int tmp = Rd_try_reload( rdec );
|
||||||
|
if( tmp > 1 ) return 5;
|
||||||
|
if( tmp ) continue;
|
||||||
if( !rdec->at_stream_end ) return 0; else break;
|
if( !rdec->at_stream_end ) return 0; else break;
|
||||||
}
|
}
|
||||||
return 4;
|
return 4;
|
||||||
|
|
108
decoder.h
108
decoder.h
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -19,17 +19,17 @@
|
||||||
|
|
||||||
enum { rd_min_available_bytes = 10 };
|
enum { rd_min_available_bytes = 10 };
|
||||||
|
|
||||||
struct Range_decoder
|
typedef struct Range_decoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb; /* input buffer */
|
Circular_buffer cb; /* input buffer */
|
||||||
unsigned long long member_position;
|
unsigned long long member_position;
|
||||||
uint32_t code;
|
uint32_t code;
|
||||||
uint32_t range;
|
uint32_t range;
|
||||||
bool at_stream_end;
|
bool at_stream_end;
|
||||||
bool reload_pending;
|
bool reload_pending;
|
||||||
};
|
} Range_decoder;
|
||||||
|
|
||||||
static inline bool Rd_init( struct Range_decoder * const rdec )
|
static inline bool Rd_init( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( !Cb_init( &rdec->cb, 65536 + rd_min_available_bytes ) ) return false;
|
if( !Cb_init( &rdec->cb, 65536 + rd_min_available_bytes ) ) return false;
|
||||||
rdec->member_position = 0;
|
rdec->member_position = 0;
|
||||||
|
@ -40,25 +40,25 @@ static inline bool Rd_init( struct Range_decoder * const rdec )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_free( struct Range_decoder * const rdec )
|
static inline void Rd_free( Range_decoder * const rdec )
|
||||||
{ Cb_free( &rdec->cb ); }
|
{ Cb_free( &rdec->cb ); }
|
||||||
|
|
||||||
static inline bool Rd_finished( const struct Range_decoder * const rdec )
|
static inline bool Rd_finished( const Range_decoder * const rdec )
|
||||||
{ return rdec->at_stream_end && Cb_empty( &rdec->cb ); }
|
{ return rdec->at_stream_end && Cb_empty( &rdec->cb ); }
|
||||||
|
|
||||||
static inline void Rd_finish( struct Range_decoder * const rdec )
|
static inline void Rd_finish( Range_decoder * const rdec )
|
||||||
{ rdec->at_stream_end = true; }
|
{ rdec->at_stream_end = true; }
|
||||||
|
|
||||||
static inline bool Rd_enough_available_bytes( const struct Range_decoder * const rdec )
|
static inline bool Rd_enough_available_bytes( const Range_decoder * const rdec )
|
||||||
{ return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; }
|
{ return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; }
|
||||||
|
|
||||||
static inline unsigned Rd_available_bytes( const struct Range_decoder * const rdec )
|
static inline unsigned Rd_available_bytes( const Range_decoder * const rdec )
|
||||||
{ return Cb_used_bytes( &rdec->cb ); }
|
{ return Cb_used_bytes( &rdec->cb ); }
|
||||||
|
|
||||||
static inline unsigned Rd_free_bytes( const struct Range_decoder * const rdec )
|
static inline unsigned Rd_free_bytes( const Range_decoder * const rdec )
|
||||||
{ return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); }
|
{ return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); }
|
||||||
|
|
||||||
static inline unsigned long long Rd_purge( struct Range_decoder * const rdec )
|
static inline unsigned long long Rd_purge( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
const unsigned long long size =
|
const unsigned long long size =
|
||||||
rdec->member_position + Cb_used_bytes( &rdec->cb );
|
rdec->member_position + Cb_used_bytes( &rdec->cb );
|
||||||
|
@ -67,7 +67,7 @@ static inline unsigned long long Rd_purge( struct Range_decoder * const rdec )
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_reset( struct Range_decoder * const rdec )
|
static inline void Rd_reset( Range_decoder * const rdec )
|
||||||
{ Cb_reset( &rdec->cb );
|
{ Cb_reset( &rdec->cb );
|
||||||
rdec->member_position = 0; rdec->at_stream_end = false; }
|
rdec->member_position = 0; rdec->at_stream_end = false; }
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ static inline void Rd_reset( struct Range_decoder * const rdec )
|
||||||
/* Seek for a member header and update 'get'. Set '*skippedp' to the number
|
/* Seek for a member header and update 'get'. Set '*skippedp' to the number
|
||||||
of bytes skipped. Return true if a valid header is found.
|
of bytes skipped. Return true if a valid header is found.
|
||||||
*/
|
*/
|
||||||
static bool Rd_find_header( struct Range_decoder * const rdec,
|
static bool Rd_find_header( Range_decoder * const rdec,
|
||||||
unsigned * const skippedp )
|
unsigned * const skippedp )
|
||||||
{
|
{
|
||||||
*skippedp = 0;
|
*skippedp = 0;
|
||||||
|
@ -101,14 +101,14 @@ static bool Rd_find_header( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline int Rd_write_data( struct Range_decoder * const rdec,
|
static inline int Rd_write_data( Range_decoder * const rdec,
|
||||||
const uint8_t * const inbuf, const int size )
|
const uint8_t * const inbuf, const int size )
|
||||||
{
|
{
|
||||||
if( rdec->at_stream_end || size <= 0 ) return 0;
|
if( rdec->at_stream_end || size <= 0 ) return 0;
|
||||||
return Cb_write_data( &rdec->cb, inbuf, size );
|
return Cb_write_data( &rdec->cb, inbuf, size );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec )
|
static inline uint8_t Rd_get_byte( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
/* 0xFF avoids decoder error if member is truncated at EOS marker */
|
/* 0xFF avoids decoder error if member is truncated at EOS marker */
|
||||||
if( Rd_finished( rdec ) ) return 0xFF;
|
if( Rd_finished( rdec ) ) return 0xFF;
|
||||||
|
@ -116,7 +116,7 @@ static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec )
|
||||||
return Cb_get_byte( &rdec->cb );
|
return Cb_get_byte( &rdec->cb );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Rd_read_data( struct Range_decoder * const rdec,
|
static inline int Rd_read_data( Range_decoder * const rdec,
|
||||||
uint8_t * const outbuf, const int size )
|
uint8_t * const outbuf, const int size )
|
||||||
{
|
{
|
||||||
const int sz = Cb_read_data( &rdec->cb, outbuf, size );
|
const int sz = Cb_read_data( &rdec->cb, outbuf, size );
|
||||||
|
@ -124,7 +124,7 @@ static inline int Rd_read_data( struct Range_decoder * const rdec,
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Rd_unread_data( struct Range_decoder * const rdec,
|
static inline bool Rd_unread_data( Range_decoder * const rdec,
|
||||||
const unsigned size )
|
const unsigned size )
|
||||||
{
|
{
|
||||||
if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) )
|
if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) )
|
||||||
|
@ -133,13 +133,15 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Rd_try_reload( struct Range_decoder * const rdec )
|
static int Rd_try_reload( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
|
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
|
||||||
{
|
{
|
||||||
rdec->reload_pending = false;
|
rdec->reload_pending = false;
|
||||||
rdec->code = 0;
|
rdec->code = 0;
|
||||||
rdec->range = 0xFFFFFFFFU;
|
rdec->range = 0xFFFFFFFFU;
|
||||||
|
/* check first byte of the LZMA stream without reading it */
|
||||||
|
if( rdec->cb.buffer[rdec->cb.get] != 0 ) return 2;
|
||||||
Rd_get_byte( rdec ); /* discard first byte of the LZMA stream */
|
Rd_get_byte( rdec ); /* discard first byte of the LZMA stream */
|
||||||
int i; for( i = 0; i < 4; ++i )
|
int i; for( i = 0; i < 4; ++i )
|
||||||
rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
|
rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
|
||||||
|
@ -147,13 +149,13 @@ static bool Rd_try_reload( struct Range_decoder * const rdec )
|
||||||
return !rdec->reload_pending;
|
return !rdec->reload_pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_normalize( struct Range_decoder * const rdec )
|
static inline void Rd_normalize( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( rdec->range <= 0x00FFFFFFU )
|
if( rdec->range <= 0x00FFFFFFU )
|
||||||
{ rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); }
|
{ rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode( Range_decoder * const rdec,
|
||||||
const int num_bits )
|
const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned symbol = 0;
|
unsigned symbol = 0;
|
||||||
|
@ -164,14 +166,14 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec,
|
||||||
rdec->range >>= 1;
|
rdec->range >>= 1;
|
||||||
/* symbol <<= 1; */
|
/* symbol <<= 1; */
|
||||||
/* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */
|
/* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */
|
||||||
const bool bit = ( rdec->code >= rdec->range );
|
const bool bit = rdec->code >= rdec->range;
|
||||||
symbol <<= 1; symbol += bit;
|
symbol <<= 1; symbol += bit;
|
||||||
rdec->code -= rdec->range & ( 0U - bit );
|
rdec->code -= rdec->range & ( 0U - bit );
|
||||||
}
|
}
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_bit( Range_decoder * const rdec,
|
||||||
Bit_model * const probability )
|
Bit_model * const probability )
|
||||||
{
|
{
|
||||||
Rd_normalize( rdec );
|
Rd_normalize( rdec );
|
||||||
|
@ -191,7 +193,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
|
static inline void Rd_decode_symbol_bit( Range_decoder * const rdec,
|
||||||
Bit_model * const probability, unsigned * symbol )
|
Bit_model * const probability, unsigned * symbol )
|
||||||
{
|
{
|
||||||
Rd_normalize( rdec );
|
Rd_normalize( rdec );
|
||||||
|
@ -211,7 +213,7 @@ static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const rdec,
|
static inline void Rd_decode_symbol_bit_reversed( Range_decoder * const rdec,
|
||||||
Bit_model * const probability, unsigned * model,
|
Bit_model * const probability, unsigned * model,
|
||||||
unsigned * symbol, const int i )
|
unsigned * symbol, const int i )
|
||||||
{
|
{
|
||||||
|
@ -233,7 +235,7 @@ static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_tree6( Range_decoder * const rdec,
|
||||||
Bit_model bm[] )
|
Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -246,7 +248,7 @@ static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
|
||||||
return symbol & 0x3F;
|
return symbol & 0x3F;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_tree8( Range_decoder * const rdec,
|
||||||
Bit_model bm[] )
|
Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -262,7 +264,7 @@ static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
Rd_decode_tree_reversed( Range_decoder * const rdec,
|
||||||
Bit_model bm[], const int num_bits )
|
Bit_model bm[], const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned model = 1;
|
unsigned model = 1;
|
||||||
|
@ -274,7 +276,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
|
Rd_decode_tree_reversed4( Range_decoder * const rdec, Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned model = 1;
|
unsigned model = 1;
|
||||||
unsigned symbol = 0;
|
unsigned symbol = 0;
|
||||||
|
@ -285,7 +287,7 @@ Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_matched( Range_decoder * const rdec,
|
||||||
Bit_model bm[], unsigned match_byte )
|
Bit_model bm[], unsigned match_byte )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -300,8 +302,8 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_len( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_len( Range_decoder * const rdec,
|
||||||
struct Len_model * const lm,
|
Len_model * const lm,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
Bit_model * bm;
|
Bit_model * bm;
|
||||||
|
@ -327,11 +329,11 @@ len3:
|
||||||
|
|
||||||
enum { lzd_min_free_bytes = max_match_len };
|
enum { lzd_min_free_bytes = max_match_len };
|
||||||
|
|
||||||
struct LZ_decoder
|
typedef struct LZ_decoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb;
|
Circular_buffer cb;
|
||||||
unsigned long long partial_data_pos;
|
unsigned long long partial_data_pos;
|
||||||
struct Range_decoder * rdec;
|
Range_decoder * rdec;
|
||||||
unsigned dictionary_size;
|
unsigned dictionary_size;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
bool check_trailer_pending;
|
bool check_trailer_pending;
|
||||||
|
@ -354,17 +356,17 @@ struct LZ_decoder
|
||||||
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
||||||
Bit_model bm_align[dis_align_size];
|
Bit_model bm_align[dis_align_size];
|
||||||
|
|
||||||
struct Len_model match_len_model;
|
Len_model match_len_model;
|
||||||
struct Len_model rep_len_model;
|
Len_model rep_len_model;
|
||||||
};
|
} LZ_decoder;
|
||||||
|
|
||||||
static inline bool LZd_enough_free_bytes( const struct LZ_decoder * const d )
|
static inline bool LZd_enough_free_bytes( const LZ_decoder * const d )
|
||||||
{ return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; }
|
{ return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; }
|
||||||
|
|
||||||
static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d )
|
static inline uint8_t LZd_peek_prev( const LZ_decoder * const d )
|
||||||
{ return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; }
|
{ return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; }
|
||||||
|
|
||||||
static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
|
static inline uint8_t LZd_peek( const LZ_decoder * const d,
|
||||||
const unsigned distance )
|
const unsigned distance )
|
||||||
{
|
{
|
||||||
const unsigned i = ( (d->cb.put > distance) ? 0 : d->cb.buffer_size ) +
|
const unsigned i = ( (d->cb.put > distance) ? 0 : d->cb.buffer_size ) +
|
||||||
|
@ -372,7 +374,7 @@ static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
|
||||||
return d->cb.buffer[i];
|
return d->cb.buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b )
|
static inline void LZd_put_byte( LZ_decoder * const d, const uint8_t b )
|
||||||
{
|
{
|
||||||
CRC32_update_byte( &d->crc, b );
|
CRC32_update_byte( &d->crc, b );
|
||||||
d->cb.buffer[d->cb.put] = b;
|
d->cb.buffer[d->cb.put] = b;
|
||||||
|
@ -380,21 +382,21 @@ static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b )
|
||||||
{ d->partial_data_pos += d->cb.put; d->cb.put = 0; d->pos_wrapped = true; }
|
{ d->partial_data_pos += d->cb.put; d->cb.put = 0; d->pos_wrapped = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_copy_block( struct LZ_decoder * const d,
|
static inline void LZd_copy_block( LZ_decoder * const d,
|
||||||
const unsigned distance, unsigned len )
|
const unsigned distance, unsigned len )
|
||||||
{
|
{
|
||||||
unsigned lpos = d->cb.put, i = lpos - distance - 1;
|
unsigned lpos = d->cb.put, i = lpos - distance - 1;
|
||||||
bool fast, fast2;
|
bool fast, fast2;
|
||||||
if( lpos > distance )
|
if( lpos > distance )
|
||||||
{
|
{
|
||||||
fast = ( len < d->cb.buffer_size - lpos );
|
fast = len < d->cb.buffer_size - lpos;
|
||||||
fast2 = ( fast && len <= lpos - i );
|
fast2 = fast && len <= lpos - i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i += d->cb.buffer_size;
|
i += d->cb.buffer_size;
|
||||||
fast = ( len < d->cb.buffer_size - i ); /* (i == pos) may happen */
|
fast = len < d->cb.buffer_size - i; /* (i == pos) may happen */
|
||||||
fast2 = ( fast && len <= i - lpos );
|
fast2 = fast && len <= i - lpos;
|
||||||
}
|
}
|
||||||
if( fast ) /* no wrap */
|
if( fast ) /* no wrap */
|
||||||
{
|
{
|
||||||
|
@ -413,8 +415,7 @@ static inline void LZd_copy_block( struct LZ_decoder * const d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZd_init( struct LZ_decoder * const d,
|
static inline bool LZd_init( LZ_decoder * const d, Range_decoder * const rde,
|
||||||
struct Range_decoder * const rde,
|
|
||||||
const unsigned dict_size )
|
const unsigned dict_size )
|
||||||
{
|
{
|
||||||
if( !Cb_init( &d->cb, max( 65536, dict_size ) + lzd_min_free_bytes ) )
|
if( !Cb_init( &d->cb, max( 65536, dict_size ) + lzd_min_free_bytes ) )
|
||||||
|
@ -449,15 +450,14 @@ static inline bool LZd_init( struct LZ_decoder * const d,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_free( struct LZ_decoder * const d )
|
static inline void LZd_free( LZ_decoder * const d ) { Cb_free( &d->cb ); }
|
||||||
{ Cb_free( &d->cb ); }
|
|
||||||
|
|
||||||
static inline bool LZd_member_finished( const struct LZ_decoder * const d )
|
static inline bool LZd_member_finished( const LZ_decoder * const d )
|
||||||
{ return d->member_finished && Cb_empty( &d->cb ); }
|
{ return d->member_finished && Cb_empty( &d->cb ); }
|
||||||
|
|
||||||
static inline unsigned LZd_crc( const struct LZ_decoder * const d )
|
static inline unsigned LZd_crc( const LZ_decoder * const d )
|
||||||
{ return d->crc ^ 0xFFFFFFFFU; }
|
{ return d->crc ^ 0xFFFFFFFFU; }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
LZd_data_position( const struct LZ_decoder * const d )
|
LZd_data_position( const LZ_decoder * const d )
|
||||||
{ return d->partial_data_pos + d->cb.put; }
|
{ return d->partial_data_pos + d->cb.put; }
|
||||||
|
|
335
doc/lzlib.info
335
doc/lzlib.info
|
@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir)
|
||||||
Lzlib Manual
|
Lzlib Manual
|
||||||
************
|
************
|
||||||
|
|
||||||
This manual is for Lzlib (version 1.15-pre1, 19 April 2024).
|
This manual is for Lzlib (version 1.15, 9 January 2025).
|
||||||
|
|
||||||
* Menu:
|
* Menu:
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@ This manual is for Lzlib (version 1.15-pre1, 19 April 2024).
|
||||||
* 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
|
* File format:: Detailed format of the compressed file
|
||||||
* 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
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 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.
|
||||||
|
@ -44,39 +44,14 @@ File: lzlib.info, Node: Introduction, Next: Library version, Prev: Top, Up:
|
||||||
Lzlib is a data compression library providing in-memory LZMA compression and
|
Lzlib is a data compression library providing in-memory LZMA compression and
|
||||||
decompression functions, including integrity checking of the decompressed
|
decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the lzip format.
|
||||||
Lzlib is written in C.
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
|
|
||||||
The lzip file format is designed for data sharing and long-term
|
|
||||||
archiving, taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
* The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program lziprecover can repair bit flip errors
|
|
||||||
(one of the most common forms of data corruption) in lzip files, and
|
|
||||||
provides data recovery capabilities, including error-checked merging
|
|
||||||
of damaged copies of a file. *Note Data safety: (lziprecover)Data
|
|
||||||
safety.
|
|
||||||
|
|
||||||
* 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
|
|
||||||
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
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
* Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
|
|
||||||
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 lziprecover, losing an entire archive just because of a corrupt
|
|
||||||
byte near the beginning is a thing of the past.
|
|
||||||
|
|
||||||
The functions and variables forming the interface of the compression
|
The functions and variables forming the interface of the compression
|
||||||
library are declared in the file 'lzlib.h'. Usage examples of the library
|
library are declared in the file 'lzlib.h'. Usage examples of the library
|
||||||
are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from
|
are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from
|
||||||
the source distribution.
|
the source distribution.
|
||||||
|
|
||||||
As 'lzlib.h' can be used by C and C++ programs, it must not impose a
|
As 'lzlib.h' can be used in C and C++ programs, it must not impose a
|
||||||
choice of system headers on the program by including one of them. Therefore
|
choice of system headers on the program by including one of them. Therefore
|
||||||
it is the responsibility of the program using lzlib to include before
|
it is the responsibility of the program using lzlib to include before
|
||||||
'lzlib.h' some header that declares the type 'uint8_t'. There are at least
|
'lzlib.h' some header that declares the type 'uint8_t'. There are at least
|
||||||
|
@ -117,10 +92,10 @@ about 2 PiB each.
|
||||||
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 '-0' of lzip uses the scheme in almost the
|
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
||||||
simplest way possible; issuing the longest match it can find, or a literal
|
simplest way possible; issuing the longest match it can find, or a literal
|
||||||
byte if it can't find a match. Inversely, a much more elaborated way of
|
byte if it can't find a match. Inversely, a more elaborate way of finding
|
||||||
finding coding sequences of minimum size than the one currently used by
|
coding sequences of minimum size than the one currently used by lzip could
|
||||||
lzip could be developed, and the resulting sequence could also be coded
|
be developed, and the resulting sequence could also be coded using the LZMA
|
||||||
using the LZMA coding scheme.
|
coding scheme.
|
||||||
|
|
||||||
Lzlib currently implements two variants of the LZMA algorithm: fast
|
Lzlib currently implements two variants of the LZMA algorithm: fast
|
||||||
(used by option '-0' of minilzip) and normal (used by all other compression
|
(used by option '-0' of minilzip) and normal (used by all other compression
|
||||||
|
@ -269,9 +244,8 @@ them return -1 or 0, for signed and unsigned return values respectively,
|
||||||
except 'LZ_compress_open' whose return value must be checked by calling
|
except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_errno' before using it.
|
'LZ_compress_errno' before using it.
|
||||||
|
|
||||||
-- Function: struct LZ_Encoder * LZ_compress_open ( const int
|
-- Function: LZ_Encoder * LZ_compress_open ( const int DICTIONARY_SIZE,
|
||||||
DICTIONARY_SIZE, const int MATCH_LEN_LIMIT, const unsigned long
|
const int MATCH_LEN_LIMIT, const unsigned long long MEMBER_SIZE )
|
||||||
long MEMBER_SIZE )
|
|
||||||
Initializes the internal stream state for compression and returns a
|
Initializes the internal stream state for compression and returns a
|
||||||
pointer that can only be used as the ENCODER argument for the other
|
pointer that can only be used as the ENCODER argument for the other
|
||||||
LZ_compress functions, or a null pointer if the encoder could not be
|
LZ_compress functions, or a null pointer if the encoder could not be
|
||||||
|
@ -303,14 +277,14 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the
|
produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the
|
||||||
uncompressed size of the member from overflowing.
|
uncompressed size of the member from overflowing.
|
||||||
|
|
||||||
-- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_close ( LZ_Encoder * const ENCODER )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to 'LZ_compress_close', ENCODER can no longer be
|
output. After a call to 'LZ_compress_close', ENCODER can no longer be
|
||||||
used as an argument to any LZ_compress function. It is safe to call
|
used as an argument to any LZ_compress function. It is safe to call
|
||||||
'LZ_compress_close' with a null argument.
|
'LZ_compress_close' with a null argument.
|
||||||
|
|
||||||
-- Function: int LZ_compress_finish ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_finish ( LZ_Encoder * const ENCODER )
|
||||||
Use this function to tell 'lzlib' that all the data for this member
|
Use this function to tell 'lzlib' that all the data for this member
|
||||||
have already been written (with the function 'LZ_compress_write'). It
|
have already been written (with the function 'LZ_compress_write'). It
|
||||||
is safe to call 'LZ_compress_finish' as many times as needed. After
|
is safe to call 'LZ_compress_finish' as many times as needed. After
|
||||||
|
@ -318,28 +292,27 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_member_finished' returns 1, a new member can be started
|
'LZ_compress_member_finished' returns 1, a new member can be started
|
||||||
with 'LZ_compress_restart_member'.
|
with 'LZ_compress_restart_member'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_restart_member ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_restart_member ( LZ_Encoder * const ENCODER,
|
||||||
ENCODER, const unsigned long long MEMBER_SIZE )
|
const unsigned long long MEMBER_SIZE )
|
||||||
Use this function to start a new member in a multimember data stream.
|
Use this function to start a new member in a multimember data stream.
|
||||||
Call this function only after 'LZ_compress_member_finished' indicates
|
Call this function only after 'LZ_compress_member_finished' indicates
|
||||||
that the current member has been fully read (with the function
|
that the current member has been fully read (with the function
|
||||||
'LZ_compress_read'). *Note member_size::, for a description of
|
'LZ_compress_read'). *Note member_size::, for a description of
|
||||||
MEMBER_SIZE.
|
MEMBER_SIZE.
|
||||||
|
|
||||||
-- Function: int LZ_compress_sync_flush ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_sync_flush ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Use this function to make available to 'LZ_compress_read' all the data
|
Use this function to make available to 'LZ_compress_read' all the data
|
||||||
already written with the function 'LZ_compress_write'. First call
|
already written with the function 'LZ_compress_write'. First call
|
||||||
'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it
|
'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it
|
||||||
returns 0.
|
returns 0.
|
||||||
|
|
||||||
This function writes at least one LZMA marker '3' ("Sync Flush" marker)
|
This function writes at least one LZMA marker '3' ('Sync Flush' marker)
|
||||||
to the compressed output. Note that the sync flush marker is not
|
to the compressed output. Note that the sync flush marker is not
|
||||||
allowed in lzip files; it is a device for interactive communication
|
allowed in lzip files; it is a device for interactive communication
|
||||||
between applications using lzlib, but is useless and wasteful in a
|
between applications using lzlib, but is useless and wasteful in a
|
||||||
file, and is excluded from the media type 'application/lzip'. The LZMA
|
file, and is excluded from the media type 'application/lzip'. The LZMA
|
||||||
marker '2' ("End Of Stream" marker) is the only marker allowed in lzip
|
marker '2' ('End Of Stream' marker) is the only marker allowed in lzip
|
||||||
files. *Note Data format::.
|
files. *Note File format::.
|
||||||
|
|
||||||
Repeated use of 'LZ_compress_sync_flush' may degrade compression
|
Repeated use of '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
|
||||||
|
@ -353,8 +326,8 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_member_finished' returns 1, followed by a new call to
|
'LZ_compress_member_finished' returns 1, followed by a new call to
|
||||||
'LZ_compress_sync_flush'.
|
'LZ_compress_sync_flush'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_read ( struct LZ_Encoder * const ENCODER,
|
-- Function: int LZ_compress_read ( LZ_Encoder * const ENCODER, uint8_t *
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
const BUFFER, const int SIZE )
|
||||||
Reads up to SIZE bytes from the stream pointed to by ENCODER, storing
|
Reads up to SIZE bytes from the stream pointed to by ENCODER, storing
|
||||||
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
||||||
pointer, in which case the bytes read are discarded.
|
pointer, in which case the bytes read are discarded.
|
||||||
|
@ -365,14 +338,13 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_write'. Note that reading less than SIZE bytes is not an
|
'LZ_compress_write'. Note that reading less than SIZE bytes is not an
|
||||||
error.
|
error.
|
||||||
|
|
||||||
-- Function: int LZ_compress_write ( struct LZ_Encoder * const ENCODER,
|
-- Function: int LZ_compress_write ( LZ_Encoder * const ENCODER, uint8_t *
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
const BUFFER, const int SIZE )
|
||||||
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
||||||
ENCODER. Returns the number of bytes actually written. This might be
|
ENCODER. Returns the number of bytes actually written. This might be
|
||||||
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
||||||
|
|
||||||
-- Function: int LZ_compress_write_size ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_write_size ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns the maximum number of bytes that can be immediately written
|
Returns the maximum number of bytes that can be immediately written
|
||||||
through 'LZ_compress_write'. For efficiency reasons, once the input
|
through 'LZ_compress_write'. For efficiency reasons, once the input
|
||||||
buffer is full and 'LZ_compress_write_size' returns 0, almost all the
|
buffer is full and 'LZ_compress_write_size' returns 0, almost all the
|
||||||
|
@ -383,39 +355,37 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
It is guaranteed that an immediate call to 'LZ_compress_write' will
|
It is guaranteed that an immediate call to 'LZ_compress_write' will
|
||||||
accept a SIZE up to the returned number of bytes.
|
accept a SIZE up to the returned number of bytes.
|
||||||
|
|
||||||
-- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * const
|
-- Function: LZ_Errno LZ_compress_errno ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns the current error code for ENCODER. *Note Error codes::. It is
|
Returns the current error code for ENCODER. *Note Error codes::. It is
|
||||||
safe to call 'LZ_compress_errno' with a null argument, in which case
|
safe to call 'LZ_compress_errno' with a null argument, in which case
|
||||||
it returns 'LZ_bad_argument'.
|
it returns 'LZ_bad_argument'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_finished ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_finished ( LZ_Encoder * const ENCODER )
|
||||||
Returns 1 if all the data have been read and 'LZ_compress_close' can
|
Returns 1 if all the data have been read and 'LZ_compress_close' can
|
||||||
be safely called. Otherwise it returns 0. 'LZ_compress_finished'
|
be safely called. Otherwise it returns 0. 'LZ_compress_finished'
|
||||||
implies 'LZ_compress_member_finished'.
|
implies 'LZ_compress_member_finished'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_member_finished ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_member_finished ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns 1 if the current member, in a multimember data stream, has been
|
Returns 1 if the current member, in a multimember data stream, has been
|
||||||
fully read and 'LZ_compress_restart_member' can be safely called.
|
fully read and 'LZ_compress_restart_member' can be safely called.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_data_position ( struct
|
-- Function: unsigned long long LZ_compress_data_position ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the number of input bytes already compressed in the current
|
Returns the number of input bytes already compressed in the current
|
||||||
member.
|
member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_member_position ( struct
|
-- Function: unsigned long long LZ_compress_member_position ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the number of compressed bytes already produced, but perhaps
|
Returns the number of compressed bytes already produced, but perhaps
|
||||||
not yet read, in the current member.
|
not yet read, in the current member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_total_in_size ( struct
|
-- Function: unsigned long long LZ_compress_total_in_size ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the total number of input bytes already compressed.
|
Returns the total number of input bytes already compressed.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_total_out_size ( struct
|
-- Function: unsigned long long LZ_compress_total_out_size ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const 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.
|
||||||
|
|
||||||
|
@ -430,7 +400,7 @@ them return -1 or 0, for signed and unsigned return values respectively,
|
||||||
except 'LZ_decompress_open' whose return value must be checked by calling
|
except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
'LZ_decompress_errno' before using it.
|
'LZ_decompress_errno' before using it.
|
||||||
|
|
||||||
-- Function: struct LZ_Decoder * LZ_decompress_open ( void )
|
-- Function: 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 DECODER argument for the other
|
pointer that can only be used as the DECODER argument for the other
|
||||||
LZ_decompress functions, or a null pointer if the decoder could not be
|
LZ_decompress functions, or a null pointer if the decoder could not be
|
||||||
|
@ -441,14 +411,14 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
returned pointer must not be used and should be freed with
|
returned pointer must not be used and should be freed with
|
||||||
'LZ_decompress_close' to avoid memory leaks.
|
'LZ_decompress_close' to avoid memory leaks.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_close ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_close ( LZ_Decoder * const DECODER )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to 'LZ_decompress_close', DECODER can no longer
|
output. After a call to 'LZ_decompress_close', DECODER can no longer
|
||||||
be used as an argument to any LZ_decompress function. It is safe to
|
be used as an argument to any LZ_decompress function. It is safe to
|
||||||
call 'LZ_decompress_close' with a null argument.
|
call 'LZ_decompress_close' with a null argument.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_finish ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_finish ( LZ_Decoder * const DECODER )
|
||||||
Use this function to tell 'lzlib' that all the data for this stream
|
Use this function to tell 'lzlib' that all the data for this stream
|
||||||
have already been written (with the function 'LZ_decompress_write').
|
have already been written (with the function 'LZ_decompress_write').
|
||||||
It is safe to call 'LZ_decompress_finish' as many times as needed. It
|
It is safe to call 'LZ_decompress_finish' as many times as needed. It
|
||||||
|
@ -456,13 +426,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
only contains whole members, but not calling it prevents lzlib from
|
only contains whole members, but not calling it prevents lzlib from
|
||||||
detecting a truncated member.
|
detecting a truncated member.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_reset ( LZ_Decoder * const DECODER )
|
||||||
Resets the internal state of DECODER as it was just after opening it
|
Resets the internal state of DECODER as it was just after opening it
|
||||||
with the function 'LZ_decompress_open'. Data stored in the internal
|
with the function 'LZ_decompress_open'. Data stored in the internal
|
||||||
buffers is discarded. Position counters are set to 0.
|
buffers are discarded. Position counters are set to 0.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_sync_to_member ( LZ_Decoder * const DECODER
|
||||||
DECODER )
|
)
|
||||||
Resets the error state of DECODER and enters a search state that lasts
|
Resets the error state of DECODER and enters a search state that lasts
|
||||||
until a new member header (or the end of the stream) is found. After a
|
until a new member header (or the end of the stream) is found. After a
|
||||||
successful call to 'LZ_decompress_sync_to_member', data written with
|
successful call to 'LZ_decompress_sync_to_member', data written with
|
||||||
|
@ -474,8 +444,8 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
case of a data error. If the decoder is already at the beginning of a
|
case of a data error. If the decoder is already at the beginning of a
|
||||||
member, this function does nothing.
|
member, this function does nothing.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER,
|
-- Function: int LZ_decompress_read ( LZ_Decoder * const DECODER, uint8_t
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
* const BUFFER, const int SIZE )
|
||||||
Reads up to SIZE bytes from the stream pointed to by DECODER, storing
|
Reads up to SIZE bytes from the stream pointed to by DECODER, storing
|
||||||
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
||||||
pointer, in which case the bytes read are discarded.
|
pointer, in which case the bytes read are discarded.
|
||||||
|
@ -500,14 +470,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
allows tools like tarlz to recover as much data as possible from each
|
allows tools like tarlz to recover as much data as possible from each
|
||||||
damaged member. *Note tarlz manual: (tarlz)Top.
|
damaged member. *Note tarlz manual: (tarlz)Top.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER,
|
-- Function: int LZ_decompress_write ( LZ_Decoder * const DECODER, uint8_t
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
* const BUFFER, const int SIZE )
|
||||||
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
||||||
DECODER. Returns the number of bytes actually written. This might be
|
DECODER. Returns the number of bytes actually written. This might be
|
||||||
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_write_size ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_write_size ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the maximum number of bytes that can be immediately written
|
Returns the maximum number of bytes that can be immediately written
|
||||||
through 'LZ_decompress_write'. This number varies smoothly; each
|
through 'LZ_decompress_write'. This number varies smoothly; each
|
||||||
compressed byte consumed may be overwritten immediately, increasing by
|
compressed byte consumed may be overwritten immediately, increasing by
|
||||||
|
@ -516,19 +485,17 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
It is guaranteed that an immediate call to 'LZ_decompress_write' will
|
It is guaranteed that an immediate call to 'LZ_decompress_write' will
|
||||||
accept a SIZE up to the returned number of bytes.
|
accept a SIZE up to the returned number of bytes.
|
||||||
|
|
||||||
-- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * const
|
-- Function: LZ_Errno LZ_decompress_errno ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the current error code for DECODER. *Note Error codes::. It is
|
Returns the current error code for DECODER. *Note Error codes::. It is
|
||||||
safe to call 'LZ_decompress_errno' with a null argument, in which case
|
safe to call 'LZ_decompress_errno' with a null argument, in which case
|
||||||
it returns 'LZ_bad_argument'.
|
it returns 'LZ_bad_argument'.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_finished ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_finished ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns 1 if all the data have been read and 'LZ_decompress_close' can
|
Returns 1 if all the data have been read and 'LZ_decompress_close' can
|
||||||
be safely called. Otherwise it returns 0. 'LZ_decompress_finished'
|
be safely called. Otherwise it returns 0. 'LZ_decompress_finished'
|
||||||
does not imply 'LZ_decompress_member_finished'.
|
does not imply 'LZ_decompress_member_finished'.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_member_finished ( LZ_Decoder * const
|
||||||
DECODER )
|
DECODER )
|
||||||
Returns 1 if the previous call to 'LZ_decompress_read' finished reading
|
Returns 1 if the previous call to 'LZ_decompress_read' finished reading
|
||||||
the current member, indicating that final values for the member are
|
the current member, indicating that final values for the member are
|
||||||
|
@ -536,37 +503,36 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
'LZ_decompress_data_position', and 'LZ_decompress_member_position'.
|
'LZ_decompress_data_position', and 'LZ_decompress_member_position'.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_member_version ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_member_version ( LZ_Decoder * const DECODER
|
||||||
DECODER )
|
)
|
||||||
Returns the version of the current member, read from the member header.
|
Returns the version of the current member, read from the member header.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_dictionary_size ( LZ_Decoder * const
|
||||||
DECODER )
|
DECODER )
|
||||||
Returns the dictionary size of the current member, read from the
|
Returns the dictionary size of the current member, read from the
|
||||||
member header.
|
member header.
|
||||||
|
|
||||||
-- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * const
|
-- Function: unsigned LZ_decompress_data_crc ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the 32 bit Cyclic Redundancy Check of the data decompressed
|
Returns the 32 bit Cyclic Redundancy Check of the data decompressed
|
||||||
from the current member. The value returned is valid only when
|
from the current member. The value returned is valid only when
|
||||||
'LZ_decompress_member_finished' returns 1.
|
'LZ_decompress_member_finished' returns 1.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_data_position ( struct
|
-- Function: unsigned long long LZ_decompress_data_position ( LZ_Decoder *
|
||||||
LZ_Decoder * const DECODER )
|
const 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.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_member_position ( struct
|
-- Function: unsigned long long LZ_decompress_member_position ( LZ_Decoder
|
||||||
LZ_Decoder * const DECODER )
|
* const DECODER )
|
||||||
Returns the number of input bytes already decompressed in the current
|
Returns the number of input bytes already decompressed in the current
|
||||||
member.
|
member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_total_in_size ( struct
|
-- Function: unsigned long long LZ_decompress_total_in_size ( LZ_Decoder *
|
||||||
LZ_Decoder * const DECODER )
|
const DECODER )
|
||||||
Returns the total number of input bytes already decompressed.
|
Returns the total number of input bytes already decompressed.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_total_out_size ( struct
|
-- Function: unsigned long long LZ_decompress_total_out_size ( LZ_Decoder
|
||||||
LZ_Decoder * const DECODER )
|
* const DECODER )
|
||||||
Returns the total number of decompressed bytes already produced, but
|
Returns the total number of decompressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
|
|
||||||
|
@ -587,42 +553,44 @@ what kind of error it was, you need to check the error code by calling
|
||||||
and you should not use 'LZ_(de)compress_errno' to determine whether a call
|
and you should not use 'LZ_(de)compress_errno' to determine whether a call
|
||||||
failed. If the call failed, then you can examine 'LZ_(de)compress_errno'.
|
failed. If the call failed, then you can examine 'LZ_(de)compress_errno'.
|
||||||
|
|
||||||
The error codes are defined in the header file 'lzlib.h'.
|
The error codes are defined in the header file 'lzlib.h'. 'LZ_Errno' is
|
||||||
|
an enum type:
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_ok
|
-- Constant: LZ_Errno LZ_ok
|
||||||
The value of this constant is 0 and is used to indicate that there is
|
The value of this constant is 0 and is used to indicate that there is
|
||||||
no error.
|
no error.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_bad_argument
|
-- Constant: LZ_Errno LZ_bad_argument
|
||||||
At least one of the arguments passed to the library function was
|
At least one of the arguments passed to the library function was
|
||||||
invalid.
|
invalid.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_mem_error
|
-- Constant: 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.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_sequence_error
|
-- Constant: LZ_Errno LZ_sequence_error
|
||||||
A library function was called in the wrong order. For example
|
A library function was called in the wrong order. For example
|
||||||
'LZ_compress_restart_member' was called before
|
'LZ_compress_restart_member' was called before
|
||||||
'LZ_compress_member_finished' indicates that the current member is
|
'LZ_compress_member_finished' indicated that the current member is
|
||||||
finished.
|
finished.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_header_error
|
-- Constant: LZ_Errno LZ_header_error
|
||||||
An invalid member header (one with the wrong magic bytes) was read. If
|
An invalid member header (one with the wrong magic bytes) was read. If
|
||||||
this happens at the end of the data stream it may indicate trailing
|
this happens at the end of the data stream it may indicate trailing
|
||||||
data.
|
data.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_unexpected_eof
|
-- Constant: LZ_Errno LZ_unexpected_eof
|
||||||
The end of the data stream was reached in the middle of a member.
|
The end of the data stream was reached in the middle of a member.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_data_error
|
-- Constant: LZ_Errno LZ_data_error
|
||||||
The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or
|
The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or
|
||||||
less, it indicates either a format version not supported, an invalid
|
less, it indicates either a format version not supported, an invalid
|
||||||
dictionary size, a corrupt header in a multimember data stream, or
|
dictionary size, a nonzero first LZMA byte, a corrupt header in a
|
||||||
trailing data too similar to a valid lzip header. Lziprecover can be
|
multimember data stream, or trailing data too similar to a valid lzip
|
||||||
used to remove conflicting trailing data from a file.
|
header. Lziprecover can be used to repair some of these errors and to
|
||||||
|
remove conflicting trailing data from a file.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_library_error
|
-- Constant: LZ_Errno LZ_library_error
|
||||||
A bug was detected in the library. Please, report it. *Note Problems::.
|
A bug was detected in the library. Please, report it. *Note Problems::.
|
||||||
|
|
||||||
|
|
||||||
|
@ -631,37 +599,37 @@ File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error
|
||||||
8 Error messages
|
8 Error messages
|
||||||
****************
|
****************
|
||||||
|
|
||||||
-- Function: const char * LZ_strerror ( const enum LZ_Errno LZ_ERRNO )
|
-- Function: const char * LZ_strerror ( const LZ_Errno LZ_ERRNO )
|
||||||
Returns the standard error message for a given error code. The messages
|
Returns the error message corresponding to the error code LZ_ERRNO.
|
||||||
are fairly short; there are no multi-line messages or embedded
|
The messages are fairly short; there are no multi-line messages or
|
||||||
newlines. This function makes it easy for your program to report
|
embedded newlines. This function makes it easy for your program to
|
||||||
informative error messages about the failure of a library call.
|
report informative error messages about the failure of a library call.
|
||||||
|
|
||||||
The value of LZ_ERRNO normally comes from a call to
|
The value of LZ_ERRNO normally comes from a call to
|
||||||
'LZ_(de)compress_errno'.
|
'LZ_(de)compress_errno'.
|
||||||
|
|
||||||
|
|
||||||
File: lzlib.info, Node: Invoking minilzip, Next: Data format, Prev: Error messages, Up: Top
|
File: lzlib.info, Node: Invoking minilzip, Next: File format, Prev: Error messages, Up: Top
|
||||||
|
|
||||||
9 Invoking minilzip
|
9 Invoking minilzip
|
||||||
*******************
|
*******************
|
||||||
|
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
installed because lzip has more features, but minilzip is well tested and
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
you can use it as your main compressor if so you wish.
|
*Note lzip: (lzip)Top.
|
||||||
|
|
||||||
Lzip is a lossless data compressor with a user interface similar to the
|
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
|
one of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov
|
||||||
chain-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
|
file can be decompressed on 32-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip (lzip -0) or compress most
|
robust 3-factor integrity checking. 'lzip -0' compresses about as fast as
|
||||||
files more than bzip2 (lzip -9). Decompression speed is intermediate between
|
gzip, while 'lzip -9' compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
perspective. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general-purpose
|
||||||
Unix-like systems.
|
compressed format for Unix-like systems.
|
||||||
|
|
||||||
The format for running minilzip is:
|
The format for running minilzip is:
|
||||||
|
|
||||||
|
@ -674,7 +642,7 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
'./' to any file name beginning with a hyphen, or use '--'.
|
'./' to any file name beginning with a hyphen, or use '--'.
|
||||||
|
|
||||||
minilzip supports the following options: *Note Argument syntax:
|
minilzip supports the following options: *Note Argument syntax:
|
||||||
(arg_parser)Argument syntax.
|
(plzip)Argument syntax.
|
||||||
|
|
||||||
'-h'
|
'-h'
|
||||||
'--help'
|
'--help'
|
||||||
|
@ -693,11 +661,12 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
|
|
||||||
'-b BYTES'
|
'-b BYTES'
|
||||||
'--member-size=BYTES'
|
'--member-size=BYTES'
|
||||||
When compressing, set the member size limit to BYTES. It is advisable
|
When compressing, set the member size limit to BYTES. If BYTES is
|
||||||
to keep members smaller than RAM size so that they can be repaired with
|
smaller than the compressed size, a multimember file is produced. It is
|
||||||
lziprecover in case of corruption. A small member size may degrade
|
advisable to keep members smaller than RAM size so that they can be
|
||||||
compression ratio, so use it only when needed. Valid values range from
|
repaired with lziprecover in case of corruption. A small member size
|
||||||
100 kB to 2 PiB. Defaults to 2 PiB.
|
may degrade compression ratio, so use it only when needed. Valid
|
||||||
|
values range from 100 kB to 2 PiB. Defaults to 2 PiB.
|
||||||
|
|
||||||
'-c'
|
'-c'
|
||||||
'--stdout'
|
'--stdout'
|
||||||
|
@ -718,7 +687,8 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
status 1. If a file fails to decompress, or is a terminal, minilzip
|
status 1. If a file fails to decompress, or is a terminal, minilzip
|
||||||
exits immediately with error status 2 without decompressing the rest
|
exits immediately with error status 2 without decompressing the rest
|
||||||
of the files. A terminal is considered an uncompressed file, and
|
of the files. A terminal is considered an uncompressed file, and
|
||||||
therefore invalid.
|
therefore invalid. A multimember file with one or more empty members
|
||||||
|
is accepted if redirected to standard input.
|
||||||
|
|
||||||
'-f'
|
'-f'
|
||||||
'--force'
|
'--force'
|
||||||
|
@ -771,6 +741,8 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
For maximum compression you should use a dictionary size limit as large
|
For maximum compression you should use a dictionary size limit as large
|
||||||
as possible, but keep in mind that the decompression memory requirement
|
as possible, but keep in mind that the decompression memory requirement
|
||||||
is affected at compression time by the choice of dictionary size limit.
|
is affected at compression time by the choice of dictionary size limit.
|
||||||
|
The dictionary size used for decompression is the same dictionary size
|
||||||
|
used for compression.
|
||||||
|
|
||||||
'-S BYTES'
|
'-S BYTES'
|
||||||
'--volume-size=BYTES'
|
'--volume-size=BYTES'
|
||||||
|
@ -790,7 +762,8 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
fails the test, does not exist, can't be opened, or is a terminal,
|
fails the test, does not exist, can't be opened, or is a terminal,
|
||||||
minilzip continues testing the rest of the files. A final diagnostic
|
minilzip continues testing the rest of the files. A final diagnostic
|
||||||
is shown at verbosity level 1 or higher if any file fails the test
|
is shown at verbosity level 1 or higher if any file fails the test
|
||||||
when testing multiple files.
|
when testing multiple files. A multimember file with one or more empty
|
||||||
|
members is accepted if redirected to standard input.
|
||||||
|
|
||||||
'-v'
|
'-v'
|
||||||
'--verbose'
|
'--verbose'
|
||||||
|
@ -818,6 +791,7 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
'-s64MiB -m273'
|
'-s64MiB -m273'
|
||||||
|
|
||||||
Level Dictionary size (-s) Match length limit (-m)
|
Level Dictionary size (-s) Match length limit (-m)
|
||||||
|
------------------------------------------------------
|
||||||
-0 64 KiB 16 bytes
|
-0 64 KiB 16 bytes
|
||||||
-1 1 MiB 5 bytes
|
-1 1 MiB 5 bytes
|
||||||
-2 1.5 MiB 6 bytes
|
-2 1.5 MiB 6 bytes
|
||||||
|
@ -837,7 +811,7 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
When decompressing or testing, allow trailing data whose first bytes
|
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
|
are 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
|
confused with a corrupt header. Use this option if a file triggers a
|
||||||
"corrupt header" error and the cause is not indeed a corrupt header.
|
'corrupt header' error and the cause is not indeed a corrupt header.
|
||||||
|
|
||||||
'--check-lib'
|
'--check-lib'
|
||||||
Compare the version of lzlib used to compile minilzip with the version
|
Compare the version of lzlib used to compile minilzip with the version
|
||||||
|
@ -858,6 +832,7 @@ and may be followed by a multiplier and an optional 'B' for "byte".
|
||||||
Table of SI and binary prefixes (unit multipliers):
|
Table of SI and binary prefixes (unit multipliers):
|
||||||
|
|
||||||
Prefix Value | Prefix Value
|
Prefix Value | Prefix Value
|
||||||
|
----------------------------------------------------------------------
|
||||||
k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024)
|
k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024)
|
||||||
M megabyte (10^6) | Mi mebibyte (2^20)
|
M megabyte (10^6) | Mi mebibyte (2^20)
|
||||||
G gigabyte (10^9) | Gi gibibyte (2^30)
|
G gigabyte (10^9) | Gi gibibyte (2^30)
|
||||||
|
@ -876,16 +851,15 @@ corrupt or invalid input file, 3 for an internal consistency error (e.g.,
|
||||||
bug) which caused minilzip to panic.
|
bug) which caused minilzip to panic.
|
||||||
|
|
||||||
|
|
||||||
File: lzlib.info, Node: Data format, Next: Examples, Prev: Invoking minilzip, Up: Top
|
File: lzlib.info, Node: File format, Next: Examples, Prev: Invoking minilzip, Up: Top
|
||||||
|
|
||||||
10 Data format
|
10 File 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
|
||||||
|
|
||||||
|
|
||||||
In the diagram below, a box like this:
|
In the diagram below, a box like this:
|
||||||
|
|
||||||
+---+
|
+---+
|
||||||
|
@ -900,12 +874,12 @@ when there is no longer anything to take away.
|
||||||
|
|
||||||
represents a variable number of bytes.
|
represents a variable number of bytes.
|
||||||
|
|
||||||
|
A lzip file consists of one or more independent "members" (compressed data
|
||||||
Lzip data consist of one or more independent "members" (compressed data
|
sets). The members simply appear one after another in the file, with no
|
||||||
sets). The members simply appear one after another in the data stream, with
|
additional information before, between, or after them. Each member can
|
||||||
no additional information before, between, or after them. Each member can
|
|
||||||
encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The
|
encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The
|
||||||
size of a multimember data stream is unlimited.
|
size of a multimember file is unlimited. Empty members (data size = 0) are
|
||||||
|
not allowed in multimember files.
|
||||||
|
|
||||||
Each member has the following structure:
|
Each member has the following structure:
|
||||||
|
|
||||||
|
@ -933,11 +907,11 @@ size of a multimember data stream is unlimited.
|
||||||
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
||||||
|
|
||||||
'LZMA stream'
|
'LZMA stream'
|
||||||
The LZMA stream, finished by an "End Of Stream" marker. Uses default
|
The LZMA stream, terminated by an 'End Of Stream' marker. Uses default
|
||||||
values for encoder properties. *Note Stream format: (lzip)Stream
|
values for encoder properties. *Note Stream format: (lzip)Stream
|
||||||
format, for a complete description.
|
format, for a complete description.
|
||||||
Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib
|
Lzip only uses the LZMA marker '2' ('End Of Stream' marker). Lzlib
|
||||||
also uses the LZMA marker '3' ("Sync Flush" marker). *Note
|
also uses the LZMA marker '3' ('Sync Flush' marker). *Note
|
||||||
sync_flush::.
|
sync_flush::.
|
||||||
|
|
||||||
'CRC32 (4 bytes)'
|
'CRC32 (4 bytes)'
|
||||||
|
@ -955,7 +929,7 @@ size of a multimember data stream is unlimited.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
File: lzlib.info, Node: Examples, Next: Problems, Prev: Data format, Up: Top
|
File: lzlib.info, Node: Examples, Next: Problems, Prev: File format, Up: Top
|
||||||
|
|
||||||
11 A small tutorial with examples
|
11 A small tutorial with examples
|
||||||
*********************************
|
*********************************
|
||||||
|
@ -997,7 +971,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -1040,7 +1014,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
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; }
|
||||||
|
|
||||||
|
@ -1071,7 +1045,7 @@ File: lzlib.info, Node: File compression, Next: File decompression, Prev: Buf
|
||||||
|
|
||||||
File-to-file compression using LZ_compress_write_size.
|
File-to-file compression using LZ_compress_write_size.
|
||||||
|
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1104,7 +1078,7 @@ File: lzlib.info, Node: File decompression, Next: File compression mm, Prev:
|
||||||
|
|
||||||
File-to-file decompression using LZ_decompress_write_size.
|
File-to-file decompression using LZ_decompress_write_size.
|
||||||
|
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1143,8 +1117,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -1181,7 +1154,7 @@ LZ_compress_open with MEMBER_SIZE > largest 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.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1227,7 +1200,7 @@ File: lzlib.info, Node: Skipping data errors, Prev: File compression mm, Up:
|
||||||
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( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1287,13 +1260,13 @@ Concept index
|
||||||
* buffering: Buffering. (line 6)
|
* buffering: Buffering. (line 6)
|
||||||
* bugs: Problems. (line 6)
|
* bugs: Problems. (line 6)
|
||||||
* compression functions: Compression functions. (line 6)
|
* compression functions: Compression functions. (line 6)
|
||||||
* data format: Data format. (line 6)
|
|
||||||
* decompression functions: Decompression functions. (line 6)
|
* decompression functions: Decompression functions. (line 6)
|
||||||
* error codes: Error codes. (line 6)
|
* error codes: Error codes. (line 6)
|
||||||
* error messages: Error messages. (line 6)
|
* error messages: Error messages. (line 6)
|
||||||
* examples: Examples. (line 6)
|
* examples: Examples. (line 6)
|
||||||
* file compression: File compression. (line 6)
|
* file compression: File compression. (line 6)
|
||||||
* file decompression: File decompression. (line 6)
|
* file decompression: File decompression. (line 6)
|
||||||
|
* file format: File format. (line 6)
|
||||||
* getting help: Problems. (line 6)
|
* getting help: Problems. (line 6)
|
||||||
* introduction: Introduction. (line 6)
|
* introduction: Introduction. (line 6)
|
||||||
* invoking: Invoking minilzip. (line 6)
|
* invoking: Invoking minilzip. (line 6)
|
||||||
|
@ -1307,28 +1280,28 @@ Concept index
|
||||||
|
|
||||||
Tag Table:
|
Tag Table:
|
||||||
Node: Top215
|
Node: Top215
|
||||||
Node: Introduction1341
|
Node: Introduction1337
|
||||||
Node: Library version6781
|
Node: Library version5500
|
||||||
Node: Buffering9332
|
Node: Buffering8051
|
||||||
Node: Parameter limits10557
|
Node: Parameter limits9276
|
||||||
Node: Compression functions11511
|
Node: Compression functions10230
|
||||||
Ref: member_size13304
|
Ref: member_size12006
|
||||||
Ref: sync_flush15066
|
Ref: sync_flush13747
|
||||||
Node: Decompression functions19754
|
Node: Decompression functions18313
|
||||||
Node: Error codes27311
|
Node: Error codes25700
|
||||||
Node: Error messages29601
|
Node: Error messages28045
|
||||||
Node: Invoking minilzip30180
|
Node: Invoking minilzip28628
|
||||||
Node: Data format40774
|
Node: File format39710
|
||||||
Ref: coded-dict-size42220
|
Ref: coded-dict-size41208
|
||||||
Node: Examples43625
|
Node: Examples42615
|
||||||
Node: Buffer compression44586
|
Node: Buffer compression43576
|
||||||
Node: Buffer decompression46106
|
Node: Buffer decompression45089
|
||||||
Node: File compression47520
|
Node: File compression46496
|
||||||
Node: File decompression48503
|
Node: File decompression47472
|
||||||
Node: File compression mm49507
|
Node: File compression mm48469
|
||||||
Node: Skipping data errors52536
|
Node: Skipping data errors51480
|
||||||
Node: Problems53841
|
Node: Problems52778
|
||||||
Node: Concept index54402
|
Node: Concept index53339
|
||||||
|
|
||||||
End Tag Table
|
End Tag Table
|
||||||
|
|
||||||
|
|
318
doc/lzlib.texi
318
doc/lzlib.texi
|
@ -6,8 +6,8 @@
|
||||||
@finalout
|
@finalout
|
||||||
@c %**end of header
|
@c %**end of header
|
||||||
|
|
||||||
@set UPDATED 19 April 2024
|
@set UPDATED 9 January 2025
|
||||||
@set VERSION 1.15-pre1
|
@set VERSION 1.15
|
||||||
|
|
||||||
@dircategory Compression
|
@dircategory Compression
|
||||||
@direntry
|
@direntry
|
||||||
|
@ -45,14 +45,14 @@ This manual is for Lzlib (version @value{VERSION}, @value{UPDATED}).
|
||||||
* 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
|
* File format:: Detailed format of the compressed file
|
||||||
* 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-2024 Antonio Diaz Diaz.
|
Copyright @copyright{} 2009-2025 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.
|
||||||
|
@ -66,53 +66,21 @@ distribute, and modify it.
|
||||||
@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib}
|
@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib}
|
||||||
is a data compression library providing in-memory LZMA compression and
|
is a data compression library providing in-memory LZMA compression and
|
||||||
decompression functions, including integrity checking of the decompressed
|
decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the
|
||||||
Lzlib is written in C.
|
@uref{http://www.nongnu.org/lzip/lzip.html,,lzip} format.
|
||||||
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
The lzip file format is designed for data sharing and long-term archiving,
|
|
||||||
taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
@itemize @bullet
|
|
||||||
@item
|
|
||||||
The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program
|
|
||||||
@uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover}
|
|
||||||
can repair bit flip errors (one of the most common forms of data corruption)
|
|
||||||
in lzip files, and provides data recovery capabilities, including
|
|
||||||
error-checked merging of damaged copies of a file.
|
|
||||||
@ifnothtml
|
|
||||||
@xref{Data safety,,,lziprecover}.
|
|
||||||
@end ifnothtml
|
|
||||||
|
|
||||||
@item
|
|
||||||
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
|
|
||||||
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
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
@end itemize
|
|
||||||
|
|
||||||
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
|
|
||||||
lziprecover, losing an entire archive just because of a corrupt byte near
|
|
||||||
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 @file{lzlib.h}. Usage examples of the library are
|
||||||
given in the files @samp{bbexample.c}, @samp{ffexample.c}, and
|
given in the files @file{bbexample.c}, @file{ffexample.c}, and
|
||||||
@samp{minilzip.c} from the source distribution.
|
@file{minilzip.c} from the source distribution.
|
||||||
|
|
||||||
As @samp{lzlib.h} can be used by C and C++ programs, it must not impose a
|
As @file{lzlib.h} can be used in C and C++ programs, it must not impose a
|
||||||
choice of system headers on the program by including one of them. Therefore
|
choice of system headers on the program by including one of them. Therefore
|
||||||
it is the responsibility of the program using lzlib to include before
|
it is the responsibility of the program using lzlib to include before
|
||||||
@samp{lzlib.h} some header that declares the type @samp{uint8_t}. There are
|
@file{lzlib.h} some header that declares the type @samp{uint8_t}. There are
|
||||||
at least four such headers in C and C++: @samp{stdint.h}, @samp{cstdint},
|
at least four such headers in C and C++: @file{stdint.h}, @file{cstdint},
|
||||||
@samp{inttypes.h}, and @samp{cinttypes}.
|
@file{inttypes.h}, and @file{cinttypes}.
|
||||||
|
|
||||||
All the library functions are thread safe. The library does not install any
|
All the library functions are thread safe. The library does not install any
|
||||||
signal handler. The decoder checks the consistency of the compressed data,
|
signal handler. The decoder checks the consistency of the compressed data,
|
||||||
|
@ -149,10 +117,10 @@ 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 @option{-0} of lzip uses the scheme in
|
scheme". For example, the option @option{-0} of lzip uses the scheme in
|
||||||
almost the simplest way possible; issuing the longest match it can find, or
|
almost the simplest way possible; issuing the longest match it can find, or
|
||||||
a literal byte if it can't find a match. Inversely, a much more elaborated
|
a literal byte if it can't find a match. Inversely, a more elaborate way of
|
||||||
way of finding coding sequences of minimum size than the one currently used
|
finding coding sequences of minimum size than the one currently used by lzip
|
||||||
by 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 @option{-0} of minilzip) and normal (used by all other compression levels).
|
option @option{-0} of minilzip) and normal (used by all other compression levels).
|
||||||
|
@ -183,10 +151,10 @@ 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. All
|
application can use to discover the version of the library being used. All
|
||||||
of them are declared in @samp{lzlib.h}.
|
of them are declared in @file{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 @file{lzlib.h} and works as a version test
|
||||||
macro. The application should check at compile time that LZ_API_VERSION is
|
macro. The application should check 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:
|
||||||
|
|
||||||
|
@ -207,7 +175,7 @@ which allow the application to announce to the library its desire to have
|
||||||
certain symbols and prototypes exposed.
|
certain symbols and prototypes exposed.
|
||||||
|
|
||||||
@deftypefun int LZ_api_version ( void )
|
@deftypefun int LZ_api_version ( void )
|
||||||
If LZ_API_VERSION >= 1012, this function is declared in @samp{lzlib.h} (else
|
If LZ_API_VERSION >= 1012, this function is declared in @file{lzlib.h} (else
|
||||||
it doesn't exist). It returns the LZ_API_VERSION of the library object code
|
it doesn't exist). It returns the LZ_API_VERSION of the library object code
|
||||||
being used. The application should check at run time that the value
|
being used. The application should check at run time that the value
|
||||||
returned by @code{LZ_api_version} is greater than or equal to the version
|
returned by @code{LZ_api_version} is greater than or equal to the version
|
||||||
|
@ -225,7 +193,7 @@ the functionality required by the application.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
@deftypevr Constant {const char *} LZ_version_string
|
@deftypevr Constant {const char *} LZ_version_string
|
||||||
This string constant is defined in the header file @samp{lzlib.h} and
|
This string constant is defined in the header file @file{lzlib.h} and
|
||||||
represents the version of the library being used at compile time.
|
represents the version of the library being used at compile time.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
|
@ -308,7 +276,7 @@ except @samp{LZ_compress_open} whose return value must be checked by
|
||||||
calling @samp{LZ_compress_errno} before using it.
|
calling @samp{LZ_compress_errno} before using it.
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {struct LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} )
|
@deftypefun {LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} )
|
||||||
Initializes the internal stream state for compression and returns a
|
Initializes the internal stream state for compression and returns a
|
||||||
pointer that can only be used as the @var{encoder} argument for the
|
pointer that can only be used as the @var{encoder} argument for the
|
||||||
other LZ_compress functions, or a null pointer if the encoder could not
|
other LZ_compress functions, or a null pointer if the encoder could not
|
||||||
|
@ -344,7 +312,7 @@ the uncompressed size of the member from overflowing.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_close ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_close ( LZ_Encoder * const @var{encoder} )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to @samp{LZ_compress_close}, @var{encoder} can no
|
output. After a call to @samp{LZ_compress_close}, @var{encoder} can no
|
||||||
|
@ -353,7 +321,7 @@ It is safe to call @samp{LZ_compress_close} with a null argument.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_finish ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_finish ( LZ_Encoder * const @var{encoder} )
|
||||||
Use this function to tell @samp{lzlib} that all the data for this member
|
Use this function to tell @samp{lzlib} that all the data for this member
|
||||||
have already been written (with the function @samp{LZ_compress_write}).
|
have already been written (with the function @samp{LZ_compress_write}).
|
||||||
It is safe to call @samp{LZ_compress_finish} as many times as needed.
|
It is safe to call @samp{LZ_compress_finish} as many times as needed.
|
||||||
|
@ -363,7 +331,7 @@ started with @samp{LZ_compress_restart_member}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_restart_member ( struct LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} )
|
@deftypefun int LZ_compress_restart_member ( LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} )
|
||||||
Use this function to start a new member in a multimember data stream. Call
|
Use this function to start a new member in a multimember data stream. Call
|
||||||
this function only after @samp{LZ_compress_member_finished} indicates that
|
this function only after @samp{LZ_compress_member_finished} indicates that
|
||||||
the current member has been fully read (with the function
|
the current member has been fully read (with the function
|
||||||
|
@ -373,19 +341,19 @@ the current member has been fully read (with the function
|
||||||
|
|
||||||
|
|
||||||
@anchor{sync_flush}
|
@anchor{sync_flush}
|
||||||
@deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_sync_flush ( 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 at least one LZMA marker @samp{3} ("Sync Flush" marker)
|
This function writes at least one LZMA marker @samp{3} ('Sync Flush' marker)
|
||||||
to the compressed output. Note that the sync flush marker is not allowed in
|
to the compressed output. Note that the sync flush marker is not allowed in
|
||||||
lzip files; it is a device for interactive communication between
|
lzip files; it is a device for interactive communication between
|
||||||
applications using lzlib, but is useless and wasteful in a file, and is
|
applications using lzlib, but is useless and wasteful in a file, and is
|
||||||
excluded from the media type @samp{application/lzip}. The LZMA marker
|
excluded from the media type @samp{application/lzip}. The LZMA marker
|
||||||
@samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files.
|
@samp{2} ('End Of Stream' marker) is the only marker allowed in lzip files.
|
||||||
@xref{Data format}.
|
@xref{File 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
|
||||||
|
@ -401,7 +369,7 @@ are more bytes available than those needed to complete @var{member_size},
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_compress_read ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Reads up to @var{size} bytes from the stream pointed to by @var{encoder},
|
Reads up to @var{size} bytes from the stream pointed to by @var{encoder},
|
||||||
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
||||||
@var{buffer} may be a null pointer, in which case the bytes read are
|
@var{buffer} may be a null pointer, in which case the bytes read are
|
||||||
|
@ -415,7 +383,7 @@ not an error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_compress_write ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
||||||
@var{encoder}. Returns the number of bytes actually written. This might be
|
@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
|
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
||||||
|
@ -423,7 +391,7 @@ error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_write_size ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the maximum number of bytes that can be immediately written through
|
Returns the maximum number of bytes that can be immediately written through
|
||||||
@samp{LZ_compress_write}. For efficiency reasons, once the input buffer is
|
@samp{LZ_compress_write}. For efficiency reasons, once the input buffer is
|
||||||
full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must
|
full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must
|
||||||
|
@ -436,44 +404,44 @@ 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{encoder} )
|
@deftypefun {LZ_Errno} LZ_compress_errno ( LZ_Encoder * const @var{encoder} )
|
||||||
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}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_finished ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_finished ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns 1 if all the data have been read and @samp{LZ_compress_close}
|
Returns 1 if all the data have been read and @samp{LZ_compress_close}
|
||||||
can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished}
|
can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished}
|
||||||
implies @samp{LZ_compress_member_finished}.
|
implies @samp{LZ_compress_member_finished}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_member_finished ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_member_finished ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns 1 if the current member, in a multimember data stream, has been
|
Returns 1 if the current member, in a multimember data stream, has been
|
||||||
fully read and @samp{LZ_compress_restart_member} can be safely called.
|
fully read and @samp{LZ_compress_restart_member} can be safely called.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_data_position ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_data_position ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the number of input bytes already compressed in the current member.
|
Returns the number of input bytes already compressed in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_member_position ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_member_position ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the number of compressed bytes already produced, but perhaps not
|
Returns the number of compressed bytes already produced, but perhaps not
|
||||||
yet read, in the current member.
|
yet read, in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_total_in_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_total_in_size ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the total number of input bytes already compressed.
|
Returns the total number of input bytes already compressed.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_total_out_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_total_out_size ( 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
|
||||||
|
@ -489,7 +457,7 @@ except @samp{LZ_decompress_open} whose return value must be checked 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 {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 other
|
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 not be
|
LZ_decompress functions, or a null pointer if the decoder could not be
|
||||||
|
@ -502,7 +470,7 @@ the returned pointer must not be used and should be freed with
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_close ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_close ( LZ_Decoder * const @var{decoder} )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no
|
output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no
|
||||||
|
@ -511,7 +479,7 @@ It is safe to call @samp{LZ_decompress_close} with a null argument.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_finish ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_finish ( LZ_Decoder * const @var{decoder} )
|
||||||
Use this function to tell @samp{lzlib} that all the data for this stream
|
Use this function to tell @samp{lzlib} that all the data for this stream
|
||||||
have already been written (with the function @samp{LZ_decompress_write}).
|
have already been written (with the function @samp{LZ_decompress_write}).
|
||||||
It is safe to call @samp{LZ_decompress_finish} as many times as needed.
|
It is safe to call @samp{LZ_decompress_finish} as many times as needed.
|
||||||
|
@ -521,14 +489,14 @@ detecting a truncated member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_reset ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_reset ( LZ_Decoder * const @var{decoder} )
|
||||||
Resets the internal state of @var{decoder} as it was just after opening
|
Resets the internal state of @var{decoder} as it was just after opening
|
||||||
it with the function @samp{LZ_decompress_open}. Data stored in the
|
it with the function @samp{LZ_decompress_open}. Data stored in the
|
||||||
internal buffers is discarded. Position counters are set to 0.
|
internal buffers are discarded. Position counters are set to 0.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_sync_to_member ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_sync_to_member ( LZ_Decoder * const @var{decoder} )
|
||||||
Resets the error state of @var{decoder} and enters a search state that lasts
|
Resets the error state of @var{decoder} and enters a search state that lasts
|
||||||
until a new member header (or the end of the stream) is found. After a
|
until a new member header (or the end of the stream) is found. After a
|
||||||
successful call to @samp{LZ_decompress_sync_to_member}, data written with
|
successful call to @samp{LZ_decompress_sync_to_member}, data written with
|
||||||
|
@ -542,7 +510,7 @@ does nothing.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_decompress_read ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Reads up to @var{size} bytes from the stream pointed to by @var{decoder},
|
Reads up to @var{size} bytes from the stream pointed to by @var{decoder},
|
||||||
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
||||||
@var{buffer} may be a null pointer, in which case the bytes read are
|
@var{buffer} may be a null pointer, in which case the bytes read are
|
||||||
|
@ -574,7 +542,7 @@ recover as much data as possible from each damaged member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_decompress_write ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
||||||
@var{decoder}. Returns the number of bytes actually written. This might be
|
@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
|
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
||||||
|
@ -582,7 +550,7 @@ error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_write_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the maximum number of bytes that can be immediately written through
|
Returns the maximum number of bytes that can be immediately written through
|
||||||
@samp{LZ_decompress_write}. This number varies smoothly; each compressed
|
@samp{LZ_decompress_write}. This number varies smoothly; each compressed
|
||||||
byte consumed may be overwritten immediately, increasing by 1 the value
|
byte consumed may be overwritten immediately, increasing by 1 the value
|
||||||
|
@ -593,21 +561,21 @@ 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 {LZ_Errno} LZ_decompress_errno ( 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 ( 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{decoder} )
|
@deftypefun int LZ_decompress_member_finished ( LZ_Decoder * const @var{decoder} )
|
||||||
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 the 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},
|
||||||
|
@ -615,40 +583,40 @@ 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{decoder} )
|
@deftypefun int LZ_decompress_member_version ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the version of the current member, read from the 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{decoder} )
|
@deftypefun int LZ_decompress_dictionary_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the dictionary size of the current member, read from the member header.
|
Returns the dictionary size of the current member, read from the member header.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned} LZ_decompress_data_crc ( LZ_Decoder * const @var{decoder} )
|
||||||
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 value returned 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 ( 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_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_member_position ( LZ_Decoder * 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.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_total_in_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_total_in_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the total number of input bytes already decompressed.
|
Returns the total number of input bytes already decompressed.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_total_out_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_total_out_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the total number of decompressed bytes already produced, but
|
Returns the total number of decompressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
@ -670,46 +638,48 @@ 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 @file{lzlib.h}.
|
||||||
|
@samp{LZ_Errno} is an enum type:
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_ok
|
@deftypevr Constant {LZ_Errno} LZ_ok
|
||||||
The value of this constant is 0 and is used to indicate that there is no error.
|
The value of this constant is 0 and is used to indicate that there is no error.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_bad_argument
|
@deftypevr Constant {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 {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
|
||||||
because its capacity is full.
|
its capacity is full.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_sequence_error
|
@deftypevr Constant {LZ_Errno} LZ_sequence_error
|
||||||
A library function was called in the wrong order. For example
|
A library function was called in the wrong order. For example
|
||||||
@samp{LZ_compress_restart_member} was called before
|
@samp{LZ_compress_restart_member} was called before
|
||||||
@samp{LZ_compress_member_finished} indicates that the current member is
|
@samp{LZ_compress_member_finished} indicated that the current member is
|
||||||
finished.
|
finished.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_header_error
|
@deftypevr Constant {LZ_Errno} LZ_header_error
|
||||||
An invalid member header (one with the wrong magic bytes) was read. If
|
An invalid member header (one with the wrong magic bytes) was read. If this
|
||||||
this happens at the end of the data stream it may indicate trailing data.
|
happens at the end of the data stream it may indicate trailing data.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_unexpected_eof
|
@deftypevr Constant {LZ_Errno} LZ_unexpected_eof
|
||||||
The end of the data stream was reached in the middle of a member.
|
The end of the data stream was reached in the middle of a member.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_data_error
|
@deftypevr Constant {LZ_Errno} LZ_data_error
|
||||||
The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6
|
The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 or
|
||||||
or less, it indicates either a format version not supported, an invalid
|
less, it indicates either a format version not supported, an invalid
|
||||||
dictionary size, a corrupt header in a multimember data stream, or
|
dictionary size, a nonzero first LZMA byte, a corrupt header in a multimember
|
||||||
trailing data too similar to a valid lzip header. Lziprecover can be
|
data stream, or trailing data too similar to a valid lzip header.
|
||||||
used to remove conflicting trailing data from a file.
|
Lziprecover can be used to repair some of these errors and to remove
|
||||||
|
conflicting trailing data from a file.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_library_error
|
@deftypevr Constant {LZ_Errno} LZ_library_error
|
||||||
A bug was detected in the library. Please, report it. @xref{Problems}.
|
A bug was detected in the library. Please, report it. @xref{Problems}.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
|
@ -718,11 +688,11 @@ A bug was detected in the library. Please, report it. @xref{Problems}.
|
||||||
@chapter Error messages
|
@chapter Error messages
|
||||||
@cindex error messages
|
@cindex error messages
|
||||||
|
|
||||||
@deftypefun {const char *} LZ_strerror ( const enum LZ_Errno @var{lz_errno} )
|
@deftypefun {const char *} LZ_strerror ( const LZ_Errno @var{lz_errno} )
|
||||||
Returns the standard error message for a given error code. The messages
|
Returns the error message corresponding to the error code @var{lz_errno}.
|
||||||
are fairly short; there are no multi-line messages or embedded newlines.
|
The messages are fairly short; there are no multi-line messages or embedded
|
||||||
This function makes it easy for your program to report informative error
|
newlines. This function makes it easy for your program to report informative
|
||||||
messages about the failure of a library call.
|
error messages about the failure of a library call.
|
||||||
|
|
||||||
The value of @var{lz_errno} normally comes from a call to
|
The value of @var{lz_errno} normally comes from a call to
|
||||||
@samp{LZ_(de)compress_errno}.
|
@samp{LZ_(de)compress_errno}.
|
||||||
|
@ -734,23 +704,25 @@ The value of @var{lz_errno} normally comes from a call to
|
||||||
@cindex invoking
|
@cindex invoking
|
||||||
@cindex options
|
@cindex options
|
||||||
|
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
installed because lzip has more features, but minilzip is well tested and
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
you can use it as your main compressor if so you wish.
|
@ifnothtml
|
||||||
|
@xref{Top,lzip,,lzip}.
|
||||||
|
@end ifnothtml
|
||||||
|
|
||||||
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
|
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
|
||||||
is a lossless data compressor with a user interface similar to the one
|
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
|
of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov
|
||||||
chain-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
|
file can be decompressed on 32-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most
|
robust 3-factor integrity checking. @w{@samp{lzip -0}} compresses about as fast as
|
||||||
files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between
|
gzip, while @w{@samp{lzip -9}} compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
perspective. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general-purpose
|
||||||
Unix-like systems.
|
compressed format for Unix-like systems.
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
The format for running minilzip is:
|
The format for running minilzip is:
|
||||||
|
@ -766,10 +738,11 @@ argument means standard input. It can be mixed with other @var{files} and is
|
||||||
read just once, the first time it appears in the command line. Remember to
|
read just once, the first time it appears in the command line. Remember to
|
||||||
prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}.
|
prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}.
|
||||||
|
|
||||||
|
@noindent
|
||||||
minilzip supports the following
|
minilzip supports the following
|
||||||
@uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}:
|
@uref{http://www.nongnu.org/lzip/manual/plzip_manual.html#Argument-syntax,,options}:
|
||||||
@ifnothtml
|
@ifnothtml
|
||||||
@xref{Argument syntax,,,arg_parser}.
|
@xref{Argument syntax,,,plzip}.
|
||||||
@end ifnothtml
|
@end ifnothtml
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
@ -790,9 +763,10 @@ garbage that can be safely ignored.
|
||||||
|
|
||||||
@item -b @var{bytes}
|
@item -b @var{bytes}
|
||||||
@itemx --member-size=@var{bytes}
|
@itemx --member-size=@var{bytes}
|
||||||
When compressing, set the member size limit to @var{bytes}. It is advisable
|
When compressing, set the member size limit to @var{bytes}. If @var{bytes}
|
||||||
to keep members smaller than RAM size so that they can be repaired with
|
is smaller than the compressed size, a multimember file is produced. It is
|
||||||
lziprecover in case of corruption. A small member size may degrade
|
advisable to keep members smaller than RAM size so that they can be repaired
|
||||||
|
with lziprecover in case of corruption. A small member size may degrade
|
||||||
compression ratio, so use it only when needed. Valid values range from
|
compression ratio, so use it only when needed. Valid values range from
|
||||||
@w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}.
|
@w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}.
|
||||||
|
|
||||||
|
@ -814,7 +788,8 @@ already exists and @option{--force} has not been specified, minilzip continues
|
||||||
decompressing the rest of the files and exits with error status 1. If a file
|
decompressing the rest of the files and exits with error status 1. If a file
|
||||||
fails to decompress, or is a terminal, minilzip exits immediately with error
|
fails to decompress, or is a terminal, minilzip exits immediately with error
|
||||||
status 2 without decompressing the rest of the files. A terminal is
|
status 2 without decompressing the rest of the files. A terminal is
|
||||||
considered an uncompressed file, and therefore invalid.
|
considered an uncompressed file, and therefore invalid. A multimember file
|
||||||
|
with one or more empty members is accepted if redirected to standard input.
|
||||||
|
|
||||||
@item -f
|
@item -f
|
||||||
@itemx --force
|
@itemx --force
|
||||||
|
@ -823,7 +798,7 @@ 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 @file{.lz} or @file{.tlz} suffix.
|
||||||
|
|
||||||
@item -k
|
@item -k
|
||||||
@itemx --keep
|
@itemx --keep
|
||||||
|
@ -846,8 +821,8 @@ when reading from a named pipe (fifo) or from a device. @w{@option{-o -}} is
|
||||||
equivalent to @option{-c}. @option{-o} has no effect when testing.
|
equivalent to @option{-c}. @option{-o} has no effect when testing.
|
||||||
|
|
||||||
When compressing and splitting the output in volumes, @var{file} is used as
|
When compressing and splitting the output in volumes, @var{file} is used as
|
||||||
a prefix, and several files named @samp{@var{file}00001.lz},
|
a prefix, and several files named @file{@var{file}00001.lz},
|
||||||
@samp{@var{file}00002.lz}, etc, are created. In this case, only one input
|
@file{@var{file}00002.lz}, etc, are created. In this case, only one input
|
||||||
file is allowed.
|
file is allowed.
|
||||||
|
|
||||||
@item -q
|
@item -q
|
||||||
|
@ -868,12 +843,14 @@ to it.
|
||||||
For maximum compression you should use a dictionary size limit as large
|
For maximum compression you should use a dictionary size limit as large
|
||||||
as possible, but keep in mind that the decompression memory requirement
|
as possible, but keep in mind that the decompression memory requirement
|
||||||
is affected at compression time by the choice of dictionary size limit.
|
is affected at compression time by the choice of dictionary size limit.
|
||||||
|
The dictionary size used for decompression is the same dictionary size used
|
||||||
|
for compression.
|
||||||
|
|
||||||
@item -S @var{bytes}
|
@item -S @var{bytes}
|
||||||
@itemx --volume-size=@var{bytes}
|
@itemx --volume-size=@var{bytes}
|
||||||
When compressing, and @option{-c} has not been also specified, split the
|
When compressing, and @option{-c} has not been also specified, split the
|
||||||
compressed output into several volume files with names
|
compressed output into several volume files with names
|
||||||
@samp{original_name00001.lz}, @samp{original_name00002.lz}, etc, and set the
|
@file{original_name00001.lz}, @file{original_name00002.lz}, etc, and set the
|
||||||
volume size limit to @var{bytes}. Input files are kept unchanged. Each
|
volume size limit to @var{bytes}. Input files are kept unchanged. Each
|
||||||
volume is a complete, maybe multimember, lzip file. A small volume size may
|
volume is a complete, maybe multimember, lzip file. A small volume size may
|
||||||
degrade compression ratio, so use it only when needed. Valid values range
|
degrade compression ratio, so use it only when needed. Valid values range
|
||||||
|
@ -887,16 +864,16 @@ together with @option{-v} to see information about the files. If a file
|
||||||
fails the test, does not exist, can't be opened, or is a terminal, minilzip
|
fails the test, does not exist, can't be opened, or is a terminal, minilzip
|
||||||
continues testing the rest of the files. A final diagnostic is shown at
|
continues testing the rest of the files. A final diagnostic is shown at
|
||||||
verbosity level 1 or higher if any file fails the test when testing multiple
|
verbosity level 1 or higher if any file fails the test when testing multiple
|
||||||
files.
|
files. A multimember file with one or more empty members is accepted if
|
||||||
|
redirected to standard input.
|
||||||
|
|
||||||
@item -v
|
@item -v
|
||||||
@itemx --verbose
|
@itemx --verbose
|
||||||
Verbose mode.@*
|
Verbose mode.@*
|
||||||
When compressing, show the compression ratio and size for each file
|
When compressing, show the compression ratio and size for each file processed.@*
|
||||||
processed.@*
|
When decompressing or testing, further -v's (up to 4) increase the verbosity
|
||||||
When decompressing or testing, further -v's (up to 4) increase the
|
level, showing status, compression ratio, dictionary size, and trailer
|
||||||
verbosity level, showing status, compression ratio, dictionary size,
|
contents (CRC, data size, member size).
|
||||||
and trailer contents (CRC, data size, member size).
|
|
||||||
|
|
||||||
@item -0 .. -9
|
@item -0 .. -9
|
||||||
Compression level. Set the compression parameters (dictionary size and
|
Compression level. Set the compression parameters (dictionary size and
|
||||||
|
@ -915,7 +892,7 @@ given, the last setting is used. For example @w{@option{-9 -s64MiB}} is
|
||||||
equivalent to @w{@option{-s64MiB -m273}}
|
equivalent to @w{@option{-s64MiB -m273}}
|
||||||
|
|
||||||
@multitable {Level} {Dictionary size (-s)} {Match length limit (-m)}
|
@multitable {Level} {Dictionary size (-s)} {Match length limit (-m)}
|
||||||
@item Level @tab Dictionary size (-s) @tab Match length limit (-m)
|
@headitem Level @tab Dictionary size (-s) @tab Match length limit (-m)
|
||||||
@item -0 @tab 64 KiB @tab 16 bytes
|
@item -0 @tab 64 KiB @tab 16 bytes
|
||||||
@item -1 @tab 1 MiB @tab 5 bytes
|
@item -1 @tab 1 MiB @tab 5 bytes
|
||||||
@item -2 @tab 1.5 MiB @tab 6 bytes
|
@item -2 @tab 1.5 MiB @tab 6 bytes
|
||||||
|
@ -935,8 +912,8 @@ 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
|
||||||
|
@ -960,7 +937,7 @@ and may be followed by a multiplier and an optional @samp{B} for "byte".
|
||||||
Table of SI and binary prefixes (unit multipliers):
|
Table of SI and binary prefixes (unit multipliers):
|
||||||
|
|
||||||
@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)}
|
@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)}
|
||||||
@item Prefix @tab Value @tab | @tab Prefix @tab Value
|
@headitem Prefix @tab Value @tab | @tab Prefix @tab Value
|
||||||
@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024)
|
@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024)
|
||||||
@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20)
|
@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20)
|
||||||
@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)
|
||||||
|
@ -980,15 +957,14 @@ indicate a corrupt or invalid input file, 3 for an internal consistency
|
||||||
error (e.g., bug) which caused minilzip to panic.
|
error (e.g., bug) which caused minilzip to panic.
|
||||||
|
|
||||||
|
|
||||||
@node Data format
|
@node File format
|
||||||
@chapter Data format
|
@chapter File format
|
||||||
@cindex data format
|
@cindex file 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
|
|
||||||
In the diagram below, a box like this:
|
In the diagram below, a box like this:
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
|
@ -1007,12 +983,13 @@ represents one byte; a box like this:
|
||||||
|
|
||||||
represents a variable number of bytes.
|
represents a variable number of bytes.
|
||||||
|
|
||||||
@sp 1
|
@noindent
|
||||||
Lzip data consist of one or more independent "members" (compressed data
|
A lzip file consists of one or more independent "members" (compressed data
|
||||||
sets). The members simply appear one after another in the data stream, with
|
sets). The members simply appear one after another in the file, with no
|
||||||
no additional information before, between, or after them. Each member can
|
additional information before, between, or after them. Each member can
|
||||||
encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data.
|
encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data.
|
||||||
The size of a multimember data stream is unlimited.
|
The size of a multimember file is unlimited. Empty members (data size = 0)
|
||||||
|
are not allowed in multimember files.
|
||||||
|
|
||||||
Each member has the following structure:
|
Each member has the following structure:
|
||||||
|
|
||||||
|
@ -1043,7 +1020,7 @@ 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, terminated 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},
|
||||||
|
@ -1053,8 +1030,8 @@ See
|
||||||
@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream format}
|
@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream format}
|
||||||
@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 original uncompressed data.
|
Cyclic Redundancy Check (CRC) of the original uncompressed data.
|
||||||
|
@ -1077,8 +1054,8 @@ overflowing.
|
||||||
@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 @file{bbexample.c} and
|
||||||
@samp{ffexample.c} from the source distribution of lzlib.
|
@file{ffexample.c} from the source distribution of lzlib.
|
||||||
|
|
||||||
Note that the interface of lzlib is symmetrical. That is, the code for
|
Note that the interface of lzlib is symmetrical. That is, the code for
|
||||||
normal compression and decompression is identical except because one calls
|
normal compression and decompression is identical except because one calls
|
||||||
|
@ -1114,7 +1091,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -1158,7 +1135,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
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; }
|
||||||
|
|
||||||
|
@ -1190,7 +1167,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
File-to-file compression using LZ_compress_write_size.
|
File-to-file compression using LZ_compress_write_size.
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1224,7 +1201,7 @@ int ffcompress( struct LZ_Encoder * const encoder,
|
||||||
File-to-file decompression using LZ_decompress_write_size.
|
File-to-file decompression using LZ_decompress_write_size.
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1264,8 +1241,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -1305,7 +1281,7 @@ Example 2: Multimember compression (user-restarted members).
|
||||||
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.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1352,7 +1328,7 @@ int fflfcompress( struct LZ_Encoder * const encoder,
|
||||||
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( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
||||||
.TH MINILZIP "1" "April 2024" "minilzip 1.15-pre1" "User Commands"
|
.TH MINILZIP "1" "January 2025" "minilzip 1.15" "User Commands"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
minilzip \- reduces the size of files
|
minilzip \- reduces the size of files
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B minilzip
|
.B minilzip
|
||||||
[\fI\,options\/\fR] [\fI\,files\/\fR]
|
[\fI\,options\/\fR] [\fI\,files\/\fR]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer.
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
.PP
|
.PP
|
||||||
Lzip is a lossless data compressor with a user interface similar to the one
|
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
|
of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel\-Ziv\-Markov
|
||||||
chain\-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain\-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity
|
file can be decompressed on 32\-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most
|
robust 3\-factor integrity checking. 'lzip \fB\-0\fR' compresses about as fast as
|
||||||
files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between
|
gzip, while 'lzip \fB\-9\fR' compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
perspective. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general\-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general\-purpose
|
||||||
Unix\-like systems.
|
compressed format for Unix\-like systems.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-h\fR, \fB\-\-help\fR
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
|
@ -32,7 +33,7 @@ output version information and exit
|
||||||
exit with error status if trailing data
|
exit with error status if trailing data
|
||||||
.TP
|
.TP
|
||||||
\fB\-b\fR, \fB\-\-member\-size=\fR<bytes>
|
\fB\-b\fR, \fB\-\-member\-size=\fR<bytes>
|
||||||
set member size limit in bytes
|
set member size limit of multimember files
|
||||||
.TP
|
.TP
|
||||||
\fB\-c\fR, \fB\-\-stdout\fR
|
\fB\-c\fR, \fB\-\-stdout\fR
|
||||||
write to standard output, keep input files
|
write to standard output, keep input files
|
||||||
|
@ -115,12 +116,12 @@ Report bugs to lzip\-bug@nongnu.org
|
||||||
.br
|
.br
|
||||||
Lzlib home page: http://www.nongnu.org/lzip/lzlib.html
|
Lzlib home page: http://www.nongnu.org/lzip/lzlib.html
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
Copyright \(co 2024 Antonio Diaz Diaz.
|
Copyright \(co 2025 Antonio Diaz Diaz.
|
||||||
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
|
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
|
||||||
.br
|
.br
|
||||||
This is free software: you are free to change and redistribute it.
|
This is free software: you are free to change and redistribute it.
|
||||||
There is NO WARRANTY, to the extent permitted by law.
|
There is NO WARRANTY, to the extent permitted by law.
|
||||||
Using lzlib 1.15\-pre1
|
Using lzlib 1.15
|
||||||
Using LZ_API_VERSION = 1015
|
Using LZ_API_VERSION = 1015
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
The full documentation for
|
The full documentation for
|
||||||
|
|
26
encoder.c
26
encoder.c
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs )
|
static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs )
|
||||||
{
|
{
|
||||||
int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 );
|
int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 );
|
||||||
int32_t * ptr1 = ptr0 + 1;
|
int32_t * ptr1 = ptr0 + 1;
|
||||||
|
@ -121,7 +121,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LZe_update_distance_prices( struct LZ_encoder * const e )
|
static void LZe_update_distance_prices( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
int dis, len_state;
|
int dis, len_state;
|
||||||
for( dis = start_dis_model; dis < modeled_distances; ++dis )
|
for( dis = start_dis_model; dis < modeled_distances; ++dis )
|
||||||
|
@ -160,7 +160,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e )
|
||||||
( trials[0].dis4 == -1 ) means literal.
|
( trials[0].dis4 == -1 ) means literal.
|
||||||
A match/rep longer or equal than match_len_limit finishes the sequence.
|
A match/rep longer or equal than match_len_limit finishes the sequence.
|
||||||
*/
|
*/
|
||||||
static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
static int LZe_sequence_optimizer( LZ_encoder * const e,
|
||||||
const int reps[num_rep_distances],
|
const int reps[num_rep_distances],
|
||||||
const State state )
|
const State state )
|
||||||
{
|
{
|
||||||
|
@ -279,7 +279,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* give final values to current trial */
|
/* give final values to current trial */
|
||||||
struct Trial * cur_trial = &e->trials[cur];
|
Trial * cur_trial = &e->trials[cur];
|
||||||
State cur_state;
|
State cur_state;
|
||||||
{
|
{
|
||||||
const int dis4 = cur_trial->dis4;
|
const int dis4 = cur_trial->dis4;
|
||||||
|
@ -291,7 +291,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
cur_state = e->trials[prev_index].state;
|
cur_state = e->trials[prev_index].state;
|
||||||
if( prev_index + 1 == cur ) /* len == 1 */
|
if( prev_index + 1 == cur ) /* len == 1 */
|
||||||
{
|
{
|
||||||
if( dis4 == 0 ) cur_state = St_set_short_rep( cur_state );
|
if( dis4 == 0 ) cur_state = St_set_shortrep( cur_state );
|
||||||
else cur_state = St_set_char( cur_state ); /* literal */
|
else cur_state = St_set_char( cur_state ); /* literal */
|
||||||
}
|
}
|
||||||
else if( dis4 < num_rep_distances ) cur_state = St_set_rep( cur_state );
|
else if( dis4 < num_rep_distances ) cur_state = St_set_rep( cur_state );
|
||||||
|
@ -324,7 +324,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte );
|
next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte );
|
||||||
|
|
||||||
/* try last updates to next trial */
|
/* try last updates to next trial */
|
||||||
struct Trial * next_trial = &e->trials[cur+1];
|
Trial * next_trial = &e->trials[cur+1];
|
||||||
|
|
||||||
Tr_update( next_trial, next_price, -1, cur ); /* literal */
|
Tr_update( next_trial, next_price, -1, cur ); /* literal */
|
||||||
|
|
||||||
|
@ -466,9 +466,9 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool LZe_encode_member( struct LZ_encoder * const e )
|
static bool LZe_encode_member( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
const bool best = ( e->match_len_limit > 12 );
|
const bool best = e->match_len_limit > 12;
|
||||||
const int dis_price_count = best ? 1 : 512;
|
const int dis_price_count = best ? 1 : 512;
|
||||||
const int align_price_count = best ? 1 : dis_align_size;
|
const int align_price_count = best ? 1 : dis_align_size;
|
||||||
const int price_count = (e->match_len_limit > 36) ? 1013 : 4093;
|
const int price_count = (e->match_len_limit > 36) ? 1013 : 4093;
|
||||||
|
@ -522,7 +522,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e )
|
||||||
const int len = e->trials[i].price;
|
const int len = e->trials[i].price;
|
||||||
int dis = e->trials[i].dis4;
|
int dis = e->trials[i].dis4;
|
||||||
|
|
||||||
bool bit = ( dis < 0 );
|
bool bit = dis < 0;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit );
|
||||||
if( bit ) /* literal byte */
|
if( bit ) /* literal byte */
|
||||||
{
|
{
|
||||||
|
@ -541,11 +541,11 @@ static bool LZe_encode_member( struct LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
CRC32_update_buf( &e->eb.crc, Mb_ptr_to_current_pos( &e->eb.mb ) - ahead, len );
|
CRC32_update_buf( &e->eb.crc, Mb_ptr_to_current_pos( &e->eb.mb ) - ahead, len );
|
||||||
mtf_reps( dis, e->eb.reps );
|
mtf_reps( dis, e->eb.reps );
|
||||||
bit = ( dis < num_rep_distances );
|
bit = dis < num_rep_distances;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep[*state], bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep[*state], bit );
|
||||||
if( bit ) /* repeated match */
|
if( bit ) /* repeated match */
|
||||||
{
|
{
|
||||||
bit = ( dis == 0 );
|
bit = dis == 0;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep0[*state], !bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep0[*state], !bit );
|
||||||
if( bit )
|
if( bit )
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_len[*state][pos_state], len > 1 );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_len[*state][pos_state], len > 1 );
|
||||||
|
@ -555,7 +555,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e )
|
||||||
if( dis > 1 )
|
if( dis > 1 )
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep2[*state], dis > 2 );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep2[*state], dis > 2 );
|
||||||
}
|
}
|
||||||
if( len == 1 ) *state = St_set_short_rep( *state );
|
if( len == 1 ) *state = St_set_shortrep( *state );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Re_encode_len( &e->eb.renc, &e->eb.rep_len_model, len, pos_state );
|
Re_encode_len( &e->eb.renc, &e->eb.rep_len_model, len, pos_state );
|
||||||
|
|
78
encoder.h
78
encoder.h
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,16 +17,16 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Len_prices
|
typedef struct Len_prices
|
||||||
{
|
{
|
||||||
const struct Len_model * lm;
|
const Len_model * lm;
|
||||||
int len_symbols;
|
int len_symbols;
|
||||||
int count;
|
int count;
|
||||||
int prices[pos_states][max_len_symbols];
|
int prices[pos_states][max_len_symbols];
|
||||||
int counters[pos_states]; /* may decrement below 0 */
|
int counters[pos_states]; /* may decrement below 0 */
|
||||||
};
|
} Len_prices;
|
||||||
|
|
||||||
static inline void Lp_update_low_mid_prices( struct Len_prices * const lp,
|
static inline void Lp_update_low_mid_prices( Len_prices * const lp,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
int * const pps = lp->prices[pos_state];
|
int * const pps = lp->prices[pos_state];
|
||||||
|
@ -41,7 +41,7 @@ static inline void Lp_update_low_mid_prices( struct Len_prices * const lp,
|
||||||
price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols );
|
price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_update_high_prices( struct Len_prices * const lp )
|
static inline void Lp_update_high_prices( Len_prices * const lp )
|
||||||
{
|
{
|
||||||
const int tmp = price1( lp->lm->choice1 ) + price1( lp->lm->choice2 );
|
const int tmp = price1( lp->lm->choice1 ) + price1( lp->lm->choice2 );
|
||||||
int len;
|
int len;
|
||||||
|
@ -52,11 +52,10 @@ static inline void Lp_update_high_prices( struct Len_prices * const lp )
|
||||||
price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols );
|
price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_reset( struct Len_prices * const lp )
|
static inline void Lp_reset( Len_prices * const lp )
|
||||||
{ int i; for( i = 0; i < pos_states; ++i ) lp->counters[i] = 0; }
|
{ int i; for( i = 0; i < pos_states; ++i ) lp->counters[i] = 0; }
|
||||||
|
|
||||||
static inline void Lp_init( struct Len_prices * const lp,
|
static inline void Lp_init( Len_prices * const lp, const Len_model * const lm,
|
||||||
const struct Len_model * const lm,
|
|
||||||
const int match_len_limit )
|
const int match_len_limit )
|
||||||
{
|
{
|
||||||
lp->lm = lm;
|
lp->lm = lm;
|
||||||
|
@ -65,11 +64,11 @@ static inline void Lp_init( struct Len_prices * const lp,
|
||||||
Lp_reset( lp );
|
Lp_reset( lp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_decrement_counter( struct Len_prices * const lp,
|
static inline void Lp_decrement_counter( Len_prices * const lp,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{ --lp->counters[pos_state]; }
|
{ --lp->counters[pos_state]; }
|
||||||
|
|
||||||
static inline void Lp_update_prices( struct Len_prices * const lp )
|
static inline void Lp_update_prices( Len_prices * const lp )
|
||||||
{
|
{
|
||||||
int pos_state;
|
int pos_state;
|
||||||
bool high_pending = false;
|
bool high_pending = false;
|
||||||
|
@ -81,23 +80,23 @@ static inline void Lp_update_prices( struct Len_prices * const lp )
|
||||||
Lp_update_high_prices( lp );
|
Lp_update_high_prices( lp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Lp_price( const struct Len_prices * const lp,
|
static inline int Lp_price( const Len_prices * const lp,
|
||||||
const int len, const int pos_state )
|
const int len, const int pos_state )
|
||||||
{ return lp->prices[pos_state][len - min_match_len]; }
|
{ return lp->prices[pos_state][len - min_match_len]; }
|
||||||
|
|
||||||
|
|
||||||
struct Pair /* distance-length pair */
|
typedef struct Pair /* distance-length pair */
|
||||||
{
|
{
|
||||||
int dis;
|
int dis;
|
||||||
int len;
|
int len;
|
||||||
};
|
} Pair;
|
||||||
|
|
||||||
enum { infinite_price = 0x0FFFFFFF,
|
enum { infinite_price = 0x0FFFFFFF,
|
||||||
max_num_trials = 1 << 13,
|
max_num_trials = 1 << 13,
|
||||||
single_step_trial = -2,
|
single_step_trial = -2,
|
||||||
dual_step_trial = -1 };
|
dual_step_trial = -1 };
|
||||||
|
|
||||||
struct Trial
|
typedef struct Trial
|
||||||
{
|
{
|
||||||
State state;
|
State state;
|
||||||
int price; /* dual use var; cumulative price, match length */
|
int price; /* dual use var; cumulative price, match length */
|
||||||
|
@ -107,9 +106,9 @@ struct Trial
|
||||||
/* -1 literal + rep0 */
|
/* -1 literal + rep0 */
|
||||||
/* >= 0 ( rep or match ) + literal + rep0 */
|
/* >= 0 ( rep or match ) + literal + rep0 */
|
||||||
int reps[num_rep_distances];
|
int reps[num_rep_distances];
|
||||||
};
|
} Trial;
|
||||||
|
|
||||||
static inline void Tr_update( struct Trial * const trial, const int pr,
|
static inline void Tr_update( Trial * const trial, const int pr,
|
||||||
const int distance4, const int p_i )
|
const int distance4, const int p_i )
|
||||||
{
|
{
|
||||||
if( pr < trial->price )
|
if( pr < trial->price )
|
||||||
|
@ -117,7 +116,7 @@ static inline void Tr_update( struct Trial * const trial, const int pr,
|
||||||
trial->prev_index2 = single_step_trial; }
|
trial->prev_index2 = single_step_trial; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Tr_update2( struct Trial * const trial, const int pr,
|
static inline void Tr_update2( Trial * const trial, const int pr,
|
||||||
const int p_i )
|
const int p_i )
|
||||||
{
|
{
|
||||||
if( pr < trial->price )
|
if( pr < trial->price )
|
||||||
|
@ -125,7 +124,7 @@ static inline void Tr_update2( struct Trial * const trial, const int pr,
|
||||||
trial->prev_index2 = dual_step_trial; }
|
trial->prev_index2 = dual_step_trial; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Tr_update3( struct Trial * const trial, const int pr,
|
static inline void Tr_update3( Trial * const trial, const int pr,
|
||||||
const int distance4, const int p_i,
|
const int distance4, const int p_i,
|
||||||
const int p_i2 )
|
const int p_i2 )
|
||||||
{
|
{
|
||||||
|
@ -135,16 +134,16 @@ static inline void Tr_update3( struct Trial * const trial, const int pr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct LZ_encoder
|
typedef struct LZ_encoder
|
||||||
{
|
{
|
||||||
struct LZ_encoder_base eb;
|
LZ_encoder_base eb;
|
||||||
int cycles;
|
int cycles;
|
||||||
int match_len_limit;
|
int match_len_limit;
|
||||||
struct Len_prices match_len_prices;
|
Len_prices match_len_prices;
|
||||||
struct Len_prices rep_len_prices;
|
Len_prices rep_len_prices;
|
||||||
int pending_num_pairs;
|
int pending_num_pairs;
|
||||||
struct Pair pairs[max_match_len+1];
|
Pair pairs[max_match_len+1];
|
||||||
struct Trial trials[max_num_trials];
|
Trial trials[max_num_trials];
|
||||||
|
|
||||||
int dis_slot_prices[len_states][2*max_dictionary_bits];
|
int dis_slot_prices[len_states][2*max_dictionary_bits];
|
||||||
int dis_prices[len_states][modeled_distances];
|
int dis_prices[len_states][modeled_distances];
|
||||||
|
@ -154,10 +153,9 @@ struct LZ_encoder
|
||||||
int dis_price_counter;
|
int dis_price_counter;
|
||||||
int align_price_counter;
|
int align_price_counter;
|
||||||
bool been_flushed;
|
bool been_flushed;
|
||||||
};
|
} LZ_encoder;
|
||||||
|
|
||||||
static inline bool Mb_dec_pos( struct Matchfinder_base * const mb,
|
static inline bool Mb_dec_pos( Matchfinder_base * const mb, const int ahead )
|
||||||
const int ahead )
|
|
||||||
{
|
{
|
||||||
if( ahead < 0 || mb->pos < ahead ) return false;
|
if( ahead < 0 || mb->pos < ahead ) return false;
|
||||||
mb->pos -= ahead;
|
mb->pos -= ahead;
|
||||||
|
@ -166,7 +164,7 @@ static inline bool Mb_dec_pos( struct Matchfinder_base * const mb,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs );
|
static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs );
|
||||||
|
|
||||||
/* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */
|
/* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */
|
||||||
static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
||||||
|
@ -184,13 +182,13 @@ static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZeb_price_shortrep( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_shortrep( const LZ_encoder_base * const eb,
|
||||||
const State state, const int pos_state )
|
const State state, const int pos_state )
|
||||||
{
|
{
|
||||||
return price0( eb->bm_rep0[state] ) + price0( eb->bm_len[state][pos_state] );
|
return price0( eb->bm_rep0[state] ) + price0( eb->bm_len[state][pos_state] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_rep( const LZ_encoder_base * const eb,
|
||||||
const int rep, const State state,
|
const int rep, const State state,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -207,7 +205,7 @@ static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb,
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_price_rep0_len( const struct LZ_encoder * const e,
|
static inline int LZe_price_rep0_len( const LZ_encoder * const e,
|
||||||
const int len, const State state,
|
const int len, const State state,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -215,7 +213,7 @@ static inline int LZe_price_rep0_len( const struct LZ_encoder * const e,
|
||||||
Lp_price( &e->rep_len_prices, len, pos_state );
|
Lp_price( &e->rep_len_prices, len, pos_state );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_price_pair( const struct LZ_encoder * const e,
|
static inline int LZe_price_pair( const LZ_encoder * const e,
|
||||||
const int dis, const int len,
|
const int dis, const int len,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -228,7 +226,7 @@ static inline int LZe_price_pair( const struct LZ_encoder * const e,
|
||||||
e->align_prices[dis & (dis_align_size - 1)];
|
e->align_prices[dis & (dis_align_size - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_read_match_distances( struct LZ_encoder * const e )
|
static inline int LZe_read_match_distances( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
const int num_pairs = LZe_get_match_pairs( e, e->pairs );
|
const int num_pairs = LZe_get_match_pairs( e, e->pairs );
|
||||||
if( num_pairs > 0 )
|
if( num_pairs > 0 )
|
||||||
|
@ -241,7 +239,7 @@ static inline int LZe_read_match_distances( struct LZ_encoder * const e )
|
||||||
return num_pairs;
|
return num_pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n )
|
static inline bool LZe_move_and_update( LZ_encoder * const e, int n )
|
||||||
{
|
{
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
|
@ -252,13 +250,13 @@ static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
static inline void LZe_backward( LZ_encoder * const e, int cur )
|
||||||
{
|
{
|
||||||
int dis4 = e->trials[cur].dis4;
|
int dis4 = e->trials[cur].dis4;
|
||||||
while( cur > 0 )
|
while( cur > 0 )
|
||||||
{
|
{
|
||||||
const int prev_index = e->trials[cur].prev_index;
|
const int prev_index = e->trials[cur].prev_index;
|
||||||
struct Trial * const prev_trial = &e->trials[prev_index];
|
Trial * const prev_trial = &e->trials[prev_index];
|
||||||
|
|
||||||
if( e->trials[cur].prev_index2 != single_step_trial )
|
if( e->trials[cur].prev_index2 != single_step_trial )
|
||||||
{
|
{
|
||||||
|
@ -267,7 +265,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
||||||
prev_trial->prev_index2 = single_step_trial;
|
prev_trial->prev_index2 = single_step_trial;
|
||||||
if( e->trials[cur].prev_index2 >= 0 )
|
if( e->trials[cur].prev_index2 >= 0 )
|
||||||
{
|
{
|
||||||
struct Trial * const prev_trial2 = &e->trials[prev_index-1];
|
Trial * const prev_trial2 = &e->trials[prev_index-1];
|
||||||
prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */
|
prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */
|
||||||
prev_trial2->prev_index = e->trials[cur].prev_index2;
|
prev_trial2->prev_index = e->trials[cur].prev_index2;
|
||||||
prev_trial2->prev_index2 = single_step_trial;
|
prev_trial2->prev_index2 = single_step_trial;
|
||||||
|
@ -282,7 +280,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
||||||
enum { num_prev_positions3 = 1 << 16,
|
enum { num_prev_positions3 = 1 << 16,
|
||||||
num_prev_positions2 = 1 << 10 };
|
num_prev_positions2 = 1 << 10 };
|
||||||
|
|
||||||
static inline bool LZe_init( struct LZ_encoder * const e,
|
static inline bool LZe_init( LZ_encoder * const e,
|
||||||
const int dict_size, const int len_limit,
|
const int dict_size, const int len_limit,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
|
@ -312,7 +310,7 @@ static inline bool LZe_init( struct LZ_encoder * const e,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZe_reset( struct LZ_encoder * const e,
|
static inline void LZe_reset( LZ_encoder * const e,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
LZeb_reset( &e->eb, member_size );
|
LZeb_reset( &e->eb, member_size );
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool Mb_normalize_pos( struct Matchfinder_base * const mb )
|
static bool Mb_normalize_pos( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( mb->pos > mb->stream_pos )
|
if( mb->pos > mb->stream_pos )
|
||||||
{ mb->pos = mb->stream_pos; return false; }
|
{ mb->pos = mb->stream_pos; return false; }
|
||||||
|
@ -40,7 +40,7 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
static bool Mb_init( Matchfinder_base * const mb, const int before_size,
|
||||||
const int dict_size, const int after_size,
|
const int dict_size, const int after_size,
|
||||||
const int dict_factor, const int num_prev_positions23,
|
const int dict_factor, const int num_prev_positions23,
|
||||||
const int pos_array_factor )
|
const int pos_array_factor )
|
||||||
|
@ -83,7 +83,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_adjust_array( struct Matchfinder_base * const mb )
|
static void Mb_adjust_array( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
|
int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
|
||||||
if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
|
if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
|
||||||
|
@ -94,7 +94,7 @@ static void Mb_adjust_array( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
|
static void Mb_adjust_dictionary_size( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( mb->stream_pos < mb->dictionary_size )
|
if( mb->stream_pos < mb->dictionary_size )
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_reset( struct Matchfinder_base * const mb )
|
static void Mb_reset( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if( mb->stream_pos > mb->pos )
|
if( mb->stream_pos > mb->pos )
|
||||||
|
@ -124,7 +124,7 @@ static void Mb_reset( struct Matchfinder_base * const mb )
|
||||||
|
|
||||||
|
|
||||||
/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */
|
/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */
|
||||||
static void LZeb_try_full_flush( struct LZ_encoder_base * const eb )
|
static void LZeb_try_full_flush( LZ_encoder_base * const eb )
|
||||||
{
|
{
|
||||||
if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) <
|
if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) <
|
||||||
max_marker_size + eb->renc.ff_count + Lt_size ) return;
|
max_marker_size + eb->renc.ff_count + Lt_size ) return;
|
||||||
|
@ -144,7 +144,7 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb )
|
||||||
|
|
||||||
|
|
||||||
/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */
|
/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */
|
||||||
static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb )
|
static void LZeb_try_sync_flush( LZ_encoder_base * const eb )
|
||||||
{
|
{
|
||||||
const unsigned min_size = eb->renc.ff_count + max_marker_size;
|
const unsigned min_size = eb->renc.ff_count + max_marker_size;
|
||||||
if( eb->member_finished ||
|
if( eb->member_finished ||
|
||||||
|
@ -163,12 +163,11 @@ static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LZeb_reset( struct LZ_encoder_base * const eb,
|
static void LZeb_reset( LZ_encoder_base * const eb,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
const unsigned long long min_member_size = min_dictionary_size;
|
const unsigned long long min_member_size = min_dictionary_size;
|
||||||
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
||||||
int i;
|
|
||||||
Mb_reset( &eb->mb );
|
Mb_reset( &eb->mb );
|
||||||
eb->member_size_limit = min( max( min_member_size, member_size ),
|
eb->member_size_limit = min( max( min_member_size, member_size ),
|
||||||
max_member_size ) - Lt_size - max_marker_size;
|
max_member_size ) - Lt_size - max_marker_size;
|
||||||
|
@ -186,7 +185,7 @@ static void LZeb_reset( struct LZ_encoder_base * const eb,
|
||||||
Lm_init( &eb->match_len_model );
|
Lm_init( &eb->match_len_model );
|
||||||
Lm_init( &eb->rep_len_model );
|
Lm_init( &eb->rep_len_model );
|
||||||
Re_reset( &eb->renc, eb->mb.dictionary_size );
|
Re_reset( &eb->renc, eb->mb.dictionary_size );
|
||||||
for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0;
|
int i; for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0;
|
||||||
eb->state = 0;
|
eb->state = 0;
|
||||||
eb->member_finished = false;
|
eb->member_finished = false;
|
||||||
}
|
}
|
||||||
|
|
114
encoder_base.h
114
encoder_base.h
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -217,7 +217,7 @@ static inline int price_matched( const Bit_model bm[], unsigned symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Matchfinder_base
|
typedef struct Matchfinder_base
|
||||||
{
|
{
|
||||||
unsigned long long partial_data_pos;
|
unsigned long long partial_data_pos;
|
||||||
uint8_t * buffer; /* input buffer */
|
uint8_t * buffer; /* input buffer */
|
||||||
|
@ -238,52 +238,52 @@ struct Matchfinder_base
|
||||||
int saved_dictionary_size; /* dictionary_size restored by Mb_reset */
|
int saved_dictionary_size; /* dictionary_size restored by Mb_reset */
|
||||||
bool at_stream_end; /* stream_pos shows real end of file */
|
bool at_stream_end; /* stream_pos shows real end of file */
|
||||||
bool sync_flush_pending;
|
bool sync_flush_pending;
|
||||||
};
|
} Matchfinder_base;
|
||||||
|
|
||||||
static bool Mb_normalize_pos( struct Matchfinder_base * const mb );
|
static bool Mb_normalize_pos( Matchfinder_base * const mb );
|
||||||
|
|
||||||
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
static bool Mb_init( Matchfinder_base * const mb, const int before_size,
|
||||||
const int dict_size, const int after_size,
|
const int dict_size, const int after_size,
|
||||||
const int dict_factor, const int num_prev_positions23,
|
const int dict_factor, const int num_prev_positions23,
|
||||||
const int pos_array_factor );
|
const int pos_array_factor );
|
||||||
|
|
||||||
static inline void Mb_free( struct Matchfinder_base * const mb )
|
static inline void Mb_free( Matchfinder_base * const mb )
|
||||||
{ free( mb->prev_positions ); free( mb->buffer ); }
|
{ free( mb->prev_positions ); free( mb->buffer ); }
|
||||||
|
|
||||||
static inline uint8_t Mb_peek( const struct Matchfinder_base * const mb,
|
static inline uint8_t Mb_peek( const Matchfinder_base * const mb,
|
||||||
const int distance )
|
const int distance )
|
||||||
{ return mb->buffer[mb->pos-distance]; }
|
{ return mb->buffer[mb->pos-distance]; }
|
||||||
|
|
||||||
static inline int Mb_available_bytes( const struct Matchfinder_base * const mb )
|
static inline int Mb_available_bytes( const Matchfinder_base * const mb )
|
||||||
{ return mb->stream_pos - mb->pos; }
|
{ return mb->stream_pos - mb->pos; }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
Mb_data_position( const struct Matchfinder_base * const mb )
|
Mb_data_position( const Matchfinder_base * const mb )
|
||||||
{ return mb->partial_data_pos + mb->pos; }
|
{ return mb->partial_data_pos + mb->pos; }
|
||||||
|
|
||||||
static inline void Mb_finish( struct Matchfinder_base * const mb )
|
static inline void Mb_finish( Matchfinder_base * const mb )
|
||||||
{ mb->at_stream_end = true; mb->sync_flush_pending = false; }
|
{ mb->at_stream_end = true; mb->sync_flush_pending = false; }
|
||||||
|
|
||||||
static inline bool Mb_data_finished( const struct Matchfinder_base * const mb )
|
static inline bool Mb_data_finished( const Matchfinder_base * const mb )
|
||||||
{ return mb->at_stream_end && mb->pos >= mb->stream_pos; }
|
{ return mb->at_stream_end && mb->pos >= mb->stream_pos; }
|
||||||
|
|
||||||
static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb )
|
static inline bool Mb_flushing_or_end( const Matchfinder_base * const mb )
|
||||||
{ return mb->at_stream_end || mb->sync_flush_pending; }
|
{ return mb->at_stream_end || mb->sync_flush_pending; }
|
||||||
|
|
||||||
static inline int Mb_free_bytes( const struct Matchfinder_base * const mb )
|
static inline int Mb_free_bytes( const Matchfinder_base * const mb )
|
||||||
{ if( Mb_flushing_or_end( mb ) ) return 0;
|
{ if( Mb_flushing_or_end( mb ) ) return 0;
|
||||||
return mb->buffer_size - mb->stream_pos; }
|
return mb->buffer_size - mb->stream_pos; }
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
Mb_enough_available_bytes( const struct Matchfinder_base * const mb )
|
Mb_enough_available_bytes( const Matchfinder_base * const mb )
|
||||||
{ return mb->pos + mb->after_size <= mb->stream_pos ||
|
{ return mb->pos + mb->after_size <= mb->stream_pos ||
|
||||||
( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); }
|
( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); }
|
||||||
|
|
||||||
static inline const uint8_t *
|
static inline const uint8_t *
|
||||||
Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb )
|
Mb_ptr_to_current_pos( const Matchfinder_base * const mb )
|
||||||
{ return mb->buffer + mb->pos; }
|
{ return mb->buffer + mb->pos; }
|
||||||
|
|
||||||
static int Mb_write_data( struct Matchfinder_base * const mb,
|
static int Mb_write_data( Matchfinder_base * const mb,
|
||||||
const uint8_t * const inbuf, const int size )
|
const uint8_t * const inbuf, const int size )
|
||||||
{
|
{
|
||||||
const int sz = min( mb->buffer_size - mb->stream_pos, size );
|
const int sz = min( mb->buffer_size - mb->stream_pos, size );
|
||||||
|
@ -293,7 +293,7 @@ static int Mb_write_data( struct Matchfinder_base * const mb,
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Mb_true_match_len( const struct Matchfinder_base * const mb,
|
static inline int Mb_true_match_len( const Matchfinder_base * const mb,
|
||||||
const int index, const int distance )
|
const int index, const int distance )
|
||||||
{
|
{
|
||||||
const uint8_t * const data = mb->buffer + mb->pos;
|
const uint8_t * const data = mb->buffer + mb->pos;
|
||||||
|
@ -303,7 +303,7 @@ static inline int Mb_true_match_len( const struct Matchfinder_base * const mb,
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Mb_move_pos( struct Matchfinder_base * const mb )
|
static inline bool Mb_move_pos( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0;
|
if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0;
|
||||||
if( ++mb->pos >= mb->pos_limit ) return Mb_normalize_pos( mb );
|
if( ++mb->pos >= mb->pos_limit ) return Mb_normalize_pos( mb );
|
||||||
|
@ -311,9 +311,9 @@ static inline bool Mb_move_pos( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Range_encoder
|
typedef struct Range_encoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb;
|
Circular_buffer cb;
|
||||||
unsigned min_free_bytes;
|
unsigned min_free_bytes;
|
||||||
uint64_t low;
|
uint64_t low;
|
||||||
unsigned long long partial_member_pos;
|
unsigned long long partial_member_pos;
|
||||||
|
@ -321,13 +321,13 @@ struct Range_encoder
|
||||||
unsigned ff_count;
|
unsigned ff_count;
|
||||||
uint8_t cache;
|
uint8_t cache;
|
||||||
Lzip_header header;
|
Lzip_header header;
|
||||||
};
|
} Range_encoder;
|
||||||
|
|
||||||
static inline void Re_shift_low( struct Range_encoder * const renc )
|
static inline void Re_shift_low( Range_encoder * const renc )
|
||||||
{
|
{
|
||||||
if( renc->low >> 24 != 0xFF )
|
if( renc->low >> 24 != 0xFF )
|
||||||
{
|
{
|
||||||
const bool carry = ( renc->low > 0xFFFFFFFFU );
|
const bool carry = renc->low > 0xFFFFFFFFU;
|
||||||
Cb_put_byte( &renc->cb, renc->cache + carry );
|
Cb_put_byte( &renc->cb, renc->cache + carry );
|
||||||
for( ; renc->ff_count > 0; --renc->ff_count )
|
for( ; renc->ff_count > 0; --renc->ff_count )
|
||||||
Cb_put_byte( &renc->cb, 0xFF + carry );
|
Cb_put_byte( &renc->cb, 0xFF + carry );
|
||||||
|
@ -337,7 +337,7 @@ static inline void Re_shift_low( struct Range_encoder * const renc )
|
||||||
renc->low = ( renc->low & 0x00FFFFFFU ) << 8;
|
renc->low = ( renc->low & 0x00FFFFFFU ) << 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_reset( struct Range_encoder * const renc,
|
static inline void Re_reset( Range_encoder * const renc,
|
||||||
const unsigned dictionary_size )
|
const unsigned dictionary_size )
|
||||||
{
|
{
|
||||||
Cb_reset( &renc->cb );
|
Cb_reset( &renc->cb );
|
||||||
|
@ -350,7 +350,7 @@ static inline void Re_reset( struct Range_encoder * const renc,
|
||||||
int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] );
|
int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Re_init( struct Range_encoder * const renc,
|
static inline bool Re_init( Range_encoder * const renc,
|
||||||
const unsigned dictionary_size,
|
const unsigned dictionary_size,
|
||||||
const unsigned min_free_bytes )
|
const unsigned min_free_bytes )
|
||||||
{
|
{
|
||||||
|
@ -361,17 +361,17 @@ static inline bool Re_init( struct Range_encoder * const renc,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_free( struct Range_encoder * const renc )
|
static inline void Re_free( Range_encoder * const renc )
|
||||||
{ Cb_free( &renc->cb ); }
|
{ Cb_free( &renc->cb ); }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
Re_member_position( const struct Range_encoder * const renc )
|
Re_member_position( const Range_encoder * const renc )
|
||||||
{ return renc->partial_member_pos + Cb_used_bytes( &renc->cb ) + renc->ff_count; }
|
{ return renc->partial_member_pos + Cb_used_bytes( &renc->cb ) + renc->ff_count; }
|
||||||
|
|
||||||
static inline bool Re_enough_free_bytes( const struct Range_encoder * const renc )
|
static inline bool Re_enough_free_bytes( const Range_encoder * const renc )
|
||||||
{ return Cb_free_bytes( &renc->cb ) >= renc->min_free_bytes + renc->ff_count; }
|
{ return Cb_free_bytes( &renc->cb ) >= renc->min_free_bytes + renc->ff_count; }
|
||||||
|
|
||||||
static inline int Re_read_data( struct Range_encoder * const renc,
|
static inline int Re_read_data( Range_encoder * const renc,
|
||||||
uint8_t * const out_buffer, const int out_size )
|
uint8_t * const out_buffer, const int out_size )
|
||||||
{
|
{
|
||||||
const int size = Cb_read_data( &renc->cb, out_buffer, out_size );
|
const int size = Cb_read_data( &renc->cb, out_buffer, out_size );
|
||||||
|
@ -379,7 +379,7 @@ static inline int Re_read_data( struct Range_encoder * const renc,
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_flush( struct Range_encoder * const renc )
|
static inline void Re_flush( Range_encoder * const renc )
|
||||||
{
|
{
|
||||||
int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc );
|
int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc );
|
||||||
renc->low = 0;
|
renc->low = 0;
|
||||||
|
@ -388,7 +388,7 @@ static inline void Re_flush( struct Range_encoder * const renc )
|
||||||
renc->cache = 0;
|
renc->cache = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode( struct Range_encoder * const renc,
|
static inline void Re_encode( Range_encoder * const renc,
|
||||||
const int symbol, const int num_bits )
|
const int symbol, const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
|
@ -400,7 +400,7 @@ static inline void Re_encode( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_bit( struct Range_encoder * const renc,
|
static inline void Re_encode_bit( Range_encoder * const renc,
|
||||||
Bit_model * const probability, const bool bit )
|
Bit_model * const probability, const bool bit )
|
||||||
{
|
{
|
||||||
const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability;
|
const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability;
|
||||||
|
@ -418,7 +418,7 @@ static inline void Re_encode_bit( struct Range_encoder * const renc,
|
||||||
if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); }
|
if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree3( struct Range_encoder * const renc,
|
static inline void Re_encode_tree3( Range_encoder * const renc,
|
||||||
Bit_model bm[], const int symbol )
|
Bit_model bm[], const int symbol )
|
||||||
{
|
{
|
||||||
bool bit = ( symbol >> 2 ) & 1;
|
bool bit = ( symbol >> 2 ) & 1;
|
||||||
|
@ -429,7 +429,7 @@ static inline void Re_encode_tree3( struct Range_encoder * const renc,
|
||||||
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree6( struct Range_encoder * const renc,
|
static inline void Re_encode_tree6( Range_encoder * const renc,
|
||||||
Bit_model bm[], const unsigned symbol )
|
Bit_model bm[], const unsigned symbol )
|
||||||
{
|
{
|
||||||
bool bit = ( symbol >> 5 ) & 1;
|
bool bit = ( symbol >> 5 ) & 1;
|
||||||
|
@ -446,7 +446,7 @@ static inline void Re_encode_tree6( struct Range_encoder * const renc,
|
||||||
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree8( struct Range_encoder * const renc,
|
static inline void Re_encode_tree8( Range_encoder * const renc,
|
||||||
Bit_model bm[], const int symbol )
|
Bit_model bm[], const int symbol )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int model = 1;
|
||||||
|
@ -459,7 +459,7 @@ static inline void Re_encode_tree8( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree_reversed( struct Range_encoder * const renc,
|
static inline void Re_encode_tree_reversed( Range_encoder * const renc,
|
||||||
Bit_model bm[], int symbol, const int num_bits )
|
Bit_model bm[], int symbol, const int num_bits )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int model = 1;
|
||||||
|
@ -473,7 +473,7 @@ static inline void Re_encode_tree_reversed( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_matched( struct Range_encoder * const renc,
|
static inline void Re_encode_matched( Range_encoder * const renc,
|
||||||
Bit_model bm[], unsigned symbol,
|
Bit_model bm[], unsigned symbol,
|
||||||
unsigned match_byte )
|
unsigned match_byte )
|
||||||
{
|
{
|
||||||
|
@ -489,17 +489,17 @@ static inline void Re_encode_matched( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_len( struct Range_encoder * const renc,
|
static inline void Re_encode_len( Range_encoder * const renc,
|
||||||
struct Len_model * const lm,
|
Len_model * const lm,
|
||||||
int symbol, const int pos_state )
|
int symbol, const int pos_state )
|
||||||
{
|
{
|
||||||
bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols );
|
bool bit = ( symbol -= min_match_len ) >= len_low_symbols;
|
||||||
Re_encode_bit( renc, &lm->choice1, bit );
|
Re_encode_bit( renc, &lm->choice1, bit );
|
||||||
if( !bit )
|
if( !bit )
|
||||||
Re_encode_tree3( renc, lm->bm_low[pos_state], symbol );
|
Re_encode_tree3( renc, lm->bm_low[pos_state], symbol );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bit = ( ( symbol -= len_low_symbols ) >= len_mid_symbols );
|
bit = ( symbol -= len_low_symbols ) >= len_mid_symbols;
|
||||||
Re_encode_bit( renc, &lm->choice2, bit );
|
Re_encode_bit( renc, &lm->choice2, bit );
|
||||||
if( !bit )
|
if( !bit )
|
||||||
Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol );
|
Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol );
|
||||||
|
@ -512,9 +512,9 @@ static inline void Re_encode_len( struct Range_encoder * const renc,
|
||||||
enum { max_marker_size = 16,
|
enum { max_marker_size = 16,
|
||||||
num_rep_distances = 4 }; /* must be 4 */
|
num_rep_distances = 4 }; /* must be 4 */
|
||||||
|
|
||||||
struct LZ_encoder_base
|
typedef struct LZ_encoder_base
|
||||||
{
|
{
|
||||||
struct Matchfinder_base mb;
|
Matchfinder_base mb;
|
||||||
unsigned long long member_size_limit;
|
unsigned long long member_size_limit;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
|
|
||||||
|
@ -528,18 +528,18 @@ struct LZ_encoder_base
|
||||||
Bit_model bm_dis_slot[len_states][1<<dis_slot_bits];
|
Bit_model bm_dis_slot[len_states][1<<dis_slot_bits];
|
||||||
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
||||||
Bit_model bm_align[dis_align_size];
|
Bit_model bm_align[dis_align_size];
|
||||||
struct Len_model match_len_model;
|
Len_model match_len_model;
|
||||||
struct Len_model rep_len_model;
|
Len_model rep_len_model;
|
||||||
struct Range_encoder renc;
|
Range_encoder renc;
|
||||||
int reps[num_rep_distances];
|
int reps[num_rep_distances];
|
||||||
State state;
|
State state;
|
||||||
bool member_finished;
|
bool member_finished;
|
||||||
};
|
} LZ_encoder_base;
|
||||||
|
|
||||||
static void LZeb_reset( struct LZ_encoder_base * const eb,
|
static void LZeb_reset( LZ_encoder_base * const eb,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
|
|
||||||
static inline bool LZeb_init( struct LZ_encoder_base * const eb,
|
static inline bool LZeb_init( LZ_encoder_base * const eb,
|
||||||
const int before_size, const int dict_size,
|
const int before_size, const int dict_size,
|
||||||
const int after_size, const int dict_factor,
|
const int after_size, const int dict_factor,
|
||||||
const int num_prev_positions23,
|
const int num_prev_positions23,
|
||||||
|
@ -555,34 +555,34 @@ static inline bool LZeb_init( struct LZ_encoder_base * const eb,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb )
|
static inline bool LZeb_member_finished( const LZ_encoder_base * const eb )
|
||||||
{ return eb->member_finished && Cb_empty( &eb->renc.cb ); }
|
{ return eb->member_finished && Cb_empty( &eb->renc.cb ); }
|
||||||
|
|
||||||
static inline void LZeb_free( struct LZ_encoder_base * const eb )
|
static inline void LZeb_free( LZ_encoder_base * const eb )
|
||||||
{ Re_free( &eb->renc ); Mb_free( &eb->mb ); }
|
{ Re_free( &eb->renc ); Mb_free( &eb->mb ); }
|
||||||
|
|
||||||
static inline unsigned LZeb_crc( const struct LZ_encoder_base * const eb )
|
static inline unsigned LZeb_crc( const LZ_encoder_base * const eb )
|
||||||
{ return eb->crc ^ 0xFFFFFFFFU; }
|
{ return eb->crc ^ 0xFFFFFFFFU; }
|
||||||
|
|
||||||
static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_literal( const LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol )
|
const uint8_t prev_byte, const uint8_t symbol )
|
||||||
{ return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
{ return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
||||||
|
|
||||||
static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_matched( const LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
||||||
{ return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol,
|
{ return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol,
|
||||||
match_byte ); }
|
match_byte ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_literal( LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol )
|
const uint8_t prev_byte, const uint8_t symbol )
|
||||||
{ Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
{ Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_matched( LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
||||||
{ Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)],
|
{ Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)],
|
||||||
symbol, match_byte ); }
|
symbol, match_byte ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_pair( LZ_encoder_base * const eb,
|
||||||
const unsigned dis, const int len,
|
const unsigned dis, const int len,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance )
|
static int FLZe_longest_match_len( FLZ_encoder * const fe, int * const distance )
|
||||||
{
|
{
|
||||||
enum { len_limit = 16 };
|
enum { len_limit = 16 };
|
||||||
int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos;
|
int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos;
|
||||||
|
@ -58,7 +58,7 @@ static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const di
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool FLZe_encode_member( struct FLZ_encoder * const fe )
|
static bool FLZe_encode_member( FLZ_encoder * const fe )
|
||||||
{
|
{
|
||||||
int rep = 0, i;
|
int rep = 0, i;
|
||||||
State * const state = &fe->eb.state;
|
State * const state = &fe->eb.state;
|
||||||
|
@ -142,7 +142,7 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe )
|
||||||
|
|
||||||
if( match_byte == cur_byte )
|
if( match_byte == cur_byte )
|
||||||
{
|
{
|
||||||
const int short_rep_price = price1( fe->eb.bm_match[*state][pos_state] ) +
|
const int shortrep_price = price1( fe->eb.bm_match[*state][pos_state] ) +
|
||||||
price1( fe->eb.bm_rep[*state] ) +
|
price1( fe->eb.bm_rep[*state] ) +
|
||||||
price0( fe->eb.bm_rep0[*state] ) +
|
price0( fe->eb.bm_rep0[*state] ) +
|
||||||
price0( fe->eb.bm_len[*state][pos_state] );
|
price0( fe->eb.bm_len[*state][pos_state] );
|
||||||
|
@ -151,13 +151,13 @@ static bool FLZe_encode_member( struct FLZ_encoder * const fe )
|
||||||
price += LZeb_price_literal( &fe->eb, prev_byte, cur_byte );
|
price += LZeb_price_literal( &fe->eb, prev_byte, cur_byte );
|
||||||
else
|
else
|
||||||
price += LZeb_price_matched( &fe->eb, prev_byte, cur_byte, match_byte );
|
price += LZeb_price_matched( &fe->eb, prev_byte, cur_byte, match_byte );
|
||||||
if( short_rep_price < price )
|
if( shortrep_price < price )
|
||||||
{
|
{
|
||||||
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_match[*state][pos_state], 1 );
|
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_match[*state][pos_state], 1 );
|
||||||
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep[*state], 1 );
|
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep[*state], 1 );
|
||||||
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep0[*state], 0 );
|
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_rep0[*state], 0 );
|
||||||
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_len[*state][pos_state], 0 );
|
Re_encode_bit( &fe->eb.renc, &fe->eb.bm_len[*state][pos_state], 0 );
|
||||||
*state = St_set_short_rep( *state );
|
*state = St_set_shortrep( *state );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -17,13 +17,13 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct FLZ_encoder
|
typedef struct FLZ_encoder
|
||||||
{
|
{
|
||||||
struct LZ_encoder_base eb;
|
LZ_encoder_base eb;
|
||||||
unsigned key4; /* key made from latest 4 bytes */
|
unsigned key4; /* key made from latest 4 bytes */
|
||||||
};
|
} FLZ_encoder;
|
||||||
|
|
||||||
static inline void FLZe_reset_key4( struct FLZ_encoder * const fe )
|
static inline void FLZe_reset_key4( FLZ_encoder * const fe )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
fe->key4 = 0;
|
fe->key4 = 0;
|
||||||
|
@ -31,9 +31,9 @@ static inline void FLZe_reset_key4( struct FLZ_encoder * const fe )
|
||||||
fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i];
|
fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n )
|
static inline bool FLZe_update_and_move( FLZ_encoder * const fe, int n )
|
||||||
{
|
{
|
||||||
struct Matchfinder_base * const mb = &fe->eb.mb;
|
Matchfinder_base * const mb = &fe->eb.mb;
|
||||||
while( --n >= 0 )
|
while( --n >= 0 )
|
||||||
{
|
{
|
||||||
if( Mb_available_bytes( mb ) >= 4 )
|
if( Mb_available_bytes( mb ) >= 4 )
|
||||||
|
@ -48,7 +48,7 @@ static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool FLZe_init( struct FLZ_encoder * const fe,
|
static inline bool FLZe_init( FLZ_encoder * const fe,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
enum { before_size = 0,
|
enum { before_size = 0,
|
||||||
|
@ -65,6 +65,6 @@ static inline bool FLZe_init( struct FLZ_encoder * const fe,
|
||||||
member_size );
|
member_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void FLZe_reset( struct FLZ_encoder * const fe,
|
static inline void FLZe_reset( FLZ_encoder * const fe,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{ LZeb_reset( &fe->eb, member_size ); }
|
{ LZeb_reset( &fe->eb, member_size ); }
|
||||||
|
|
20
ffexample.c
20
ffexample.c
|
@ -1,5 +1,5 @@
|
||||||
/* File to file example - Test program for the library lzlib
|
/* File to file example - Test program for the library lzlib
|
||||||
Copyright (C) 2010-2024 Antonio Diaz Diaz.
|
Copyright (C) 2010-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This program is free software: you have unlimited permission
|
This program is free software: you have unlimited permission
|
||||||
to copy, distribute, and modify it.
|
to copy, distribute, and modify it.
|
||||||
|
@ -53,7 +53,7 @@ static void show_help( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -79,7 +79,7 @@ int ffcompress( struct LZ_Encoder * const encoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -105,8 +105,7 @@ int ffdecompress( struct LZ_Decoder * const decoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffboth( struct LZ_Encoder * const encoder,
|
int ffboth( LZ_Encoder * const encoder, LZ_Decoder * const decoder,
|
||||||
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 };
|
||||||
|
@ -147,8 +146,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -182,7 +180,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
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.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -223,7 +221,7 @@ int fflfcompress( struct LZ_Encoder * const encoder,
|
||||||
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( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -262,8 +260,8 @@ int main( const int argc, const char * const argv[] )
|
||||||
setmode( STDOUT_FILENO, O_BINARY );
|
setmode( STDOUT_FILENO, O_BINARY );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX );
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX );
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
FILE * const infile = (argc >= 3 && strcmp( argv[2], "-" ) != 0) ?
|
FILE * const infile = (argc >= 3 && strcmp( argv[2], "-" ) != 0) ?
|
||||||
fopen( argv[2], "rb" ) : stdin;
|
fopen( argv[2], "rb" ) : stdin;
|
||||||
FILE * const outfile = (argc >= 4 && strcmp( argv[3], "-" ) != 0) ?
|
FILE * const outfile = (argc >= 4 && strcmp( argv[3], "-" ) != 0) ?
|
||||||
|
|
26
lzcheck.c
26
lzcheck.c
|
@ -1,5 +1,5 @@
|
||||||
/* Lzcheck - Test program for the library lzlib
|
/* Lzcheck - Test program for the library lzlib
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This program is free software: you have unlimited permission
|
This program is free software: you have unlimited permission
|
||||||
to copy, distribute, and modify it.
|
to copy, distribute, and modify it.
|
||||||
|
@ -41,10 +41,10 @@ static void show_line( const uint8_t * const buffer, const int size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct LZ_Encoder * xopen_encoder( const int dictionary_size )
|
static LZ_Encoder * xopen_encoder( const int dictionary_size )
|
||||||
{
|
{
|
||||||
const int match_len_limit = 16;
|
const int match_len_limit = 16;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, member_size );
|
LZ_compress_open( dictionary_size, match_len_limit, member_size );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{
|
{
|
||||||
|
@ -63,9 +63,9 @@ static struct LZ_Encoder * xopen_encoder( const int dictionary_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct LZ_Decoder * xopen_decoder( void )
|
static LZ_Decoder * xopen_decoder( void )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
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 );
|
LZ_decompress_close( decoder );
|
||||||
|
@ -76,8 +76,7 @@ static struct LZ_Decoder * xopen_decoder( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void xclose_encoder( struct LZ_Encoder * const encoder,
|
static void xclose_encoder( LZ_Encoder * const encoder, const bool finish )
|
||||||
const bool finish )
|
|
||||||
{
|
{
|
||||||
if( finish )
|
if( finish )
|
||||||
{
|
{
|
||||||
|
@ -105,8 +104,7 @@ static void xclose_encoder( struct LZ_Encoder * const encoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void xclose_decoder( struct LZ_Decoder * const decoder,
|
static void xclose_decoder( LZ_Decoder * const decoder, const bool finish )
|
||||||
const bool finish )
|
|
||||||
{
|
{
|
||||||
if( finish )
|
if( finish )
|
||||||
{
|
{
|
||||||
|
@ -160,8 +158,8 @@ static const uint8_t * next_line( FILE * const file, int * const sizep )
|
||||||
|
|
||||||
static int check_sync_flush( FILE * const file, const int dictionary_size )
|
static int check_sync_flush( FILE * const file, const int dictionary_size )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
||||||
struct LZ_Decoder * const decoder = xopen_decoder();
|
LZ_Decoder * const decoder = xopen_decoder();
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
while( retval <= 1 ) /* test LZ_compress_sync_flush */
|
while( retval <= 1 ) /* test LZ_compress_sync_flush */
|
||||||
|
@ -267,8 +265,8 @@ static int check_sync_flush( FILE * const file, const int dictionary_size )
|
||||||
*/
|
*/
|
||||||
static int check_members( FILE * const file, const int dictionary_size )
|
static int check_members( FILE * const file, const int dictionary_size )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
||||||
struct LZ_Decoder * const decoder = xopen_decoder();
|
LZ_Decoder * const decoder = xopen_decoder();
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
while( retval <= 1 ) /* test LZ_compress_restart_member */
|
while( retval <= 1 ) /* test LZ_compress_restart_member */
|
||||||
|
@ -362,7 +360,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ?
|
( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ?
|
||||||
argv[1][1] : 0;
|
argv[1][1] : 0;
|
||||||
const int first = opt ? 2 : 1;
|
const int first = opt ? 2 : 1;
|
||||||
const bool verbose = ( opt != 0 || argc > first + 1 );
|
const bool verbose = opt != 0 || argc > first + 1;
|
||||||
|
|
||||||
if( argc < 2 )
|
if( argc < 2 )
|
||||||
{
|
{
|
||||||
|
|
10
lzip.h
10
lzip.h
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -40,7 +40,7 @@ static inline State St_set_match( const State st )
|
||||||
{ return ( st < 7 ) ? 7 : 10; }
|
{ return ( st < 7 ) ? 7 : 10; }
|
||||||
static inline State St_set_rep( const State st )
|
static inline State St_set_rep( const State st )
|
||||||
{ return ( st < 7 ) ? 8 : 11; }
|
{ return ( st < 7 ) ? 8 : 11; }
|
||||||
static inline State St_set_short_rep( const State st )
|
static inline State St_set_shortrep( const State st )
|
||||||
{ return ( st < 7 ) ? 9 : 11; }
|
{ return ( st < 7 ) ? 9 : 11; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,16 +94,16 @@ static inline void Bm_init( Bit_model * const probability )
|
||||||
static inline void Bm_array_init( Bit_model bm[], const int size )
|
static inline void Bm_array_init( Bit_model bm[], const int size )
|
||||||
{ int i; for( i = 0; i < size; ++i ) Bm_init( &bm[i] ); }
|
{ int i; for( i = 0; i < size; ++i ) Bm_init( &bm[i] ); }
|
||||||
|
|
||||||
struct Len_model
|
typedef struct Len_model
|
||||||
{
|
{
|
||||||
Bit_model choice1;
|
Bit_model choice1;
|
||||||
Bit_model choice2;
|
Bit_model choice2;
|
||||||
Bit_model bm_low[pos_states][len_low_symbols];
|
Bit_model bm_low[pos_states][len_low_symbols];
|
||||||
Bit_model bm_mid[pos_states][len_mid_symbols];
|
Bit_model bm_mid[pos_states][len_mid_symbols];
|
||||||
Bit_model bm_high[len_high_symbols];
|
Bit_model bm_high[len_high_symbols];
|
||||||
};
|
} Len_model;
|
||||||
|
|
||||||
static inline void Lm_init( struct Len_model * const lm )
|
static inline void Lm_init( Len_model * const lm )
|
||||||
{
|
{
|
||||||
Bm_init( &lm->choice1 );
|
Bm_init( &lm->choice1 );
|
||||||
Bm_init( &lm->choice2 );
|
Bm_init( &lm->choice2 );
|
||||||
|
|
110
lzlib.c
110
lzlib.c
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -39,14 +39,14 @@ struct LZ_Encoder
|
||||||
{
|
{
|
||||||
unsigned long long partial_in_size;
|
unsigned long long partial_in_size;
|
||||||
unsigned long long partial_out_size;
|
unsigned long long partial_out_size;
|
||||||
struct LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
||||||
struct LZ_encoder * lz_encoder; /* polymorphic encoder */
|
LZ_encoder * lz_encoder; /* polymorphic encoder */
|
||||||
struct FLZ_encoder * flz_encoder;
|
FLZ_encoder * flz_encoder;
|
||||||
enum LZ_Errno lz_errno;
|
LZ_Errno lz_errno;
|
||||||
bool fatal;
|
bool fatal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void LZ_Encoder_init( struct LZ_Encoder * const e )
|
static void LZ_Encoder_init( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
e->partial_in_size = 0;
|
e->partial_in_size = 0;
|
||||||
e->partial_out_size = 0;
|
e->partial_out_size = 0;
|
||||||
|
@ -62,16 +62,16 @@ struct LZ_Decoder
|
||||||
{
|
{
|
||||||
unsigned long long partial_in_size;
|
unsigned long long partial_in_size;
|
||||||
unsigned long long partial_out_size;
|
unsigned long long partial_out_size;
|
||||||
struct Range_decoder * rdec;
|
Range_decoder * rdec;
|
||||||
struct LZ_decoder * lz_decoder;
|
LZ_decoder * lz_decoder;
|
||||||
enum LZ_Errno lz_errno;
|
LZ_Errno lz_errno;
|
||||||
Lzip_header member_header; /* header of current member */
|
Lzip_header member_header; /* header of current member */
|
||||||
bool fatal;
|
bool fatal;
|
||||||
bool first_header; /* true until first header is read */
|
bool first_header; /* true until first header is read */
|
||||||
bool seeking;
|
bool seeking;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
static void LZ_Decoder_init( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
d->partial_in_size = 0;
|
d->partial_in_size = 0;
|
||||||
|
@ -86,7 +86,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_encoder( struct LZ_Encoder * const e )
|
static bool check_encoder( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return false;
|
if( !e ) return false;
|
||||||
if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) ||
|
if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) ||
|
||||||
|
@ -96,7 +96,7 @@ static bool check_encoder( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_decoder( struct LZ_Decoder * const d )
|
static bool check_decoder( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return false;
|
if( !d ) return false;
|
||||||
if( !d->rdec )
|
if( !d->rdec )
|
||||||
|
@ -111,7 +111,7 @@ int LZ_api_version( void ) { return LZ_API_VERSION; }
|
||||||
|
|
||||||
const char * LZ_version( void ) { return LZ_version_string; }
|
const char * LZ_version( void ) { return LZ_version_string; }
|
||||||
|
|
||||||
const char * LZ_strerror( const enum LZ_Errno lz_errno )
|
const char * LZ_strerror( const LZ_Errno lz_errno )
|
||||||
{
|
{
|
||||||
switch( lz_errno )
|
switch( lz_errno )
|
||||||
{
|
{
|
||||||
|
@ -138,13 +138,12 @@ int LZ_max_match_len_limit( void ) { return max_match_len; }
|
||||||
|
|
||||||
/* --------------------- Compression Functions --------------------- */
|
/* --------------------- Compression Functions --------------------- */
|
||||||
|
|
||||||
struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
const int match_len_limit,
|
const int match_len_limit,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
Lzip_header header;
|
Lzip_header header;
|
||||||
struct LZ_Encoder * const e =
|
LZ_Encoder * const e = (LZ_Encoder *)malloc( sizeof (LZ_Encoder) );
|
||||||
(struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) );
|
|
||||||
if( !e ) return 0;
|
if( !e ) return 0;
|
||||||
LZ_Encoder_init( e );
|
LZ_Encoder_init( e );
|
||||||
if( !Lh_set_dictionary_size( header, dictionary_size ) ||
|
if( !Lh_set_dictionary_size( header, dictionary_size ) ||
|
||||||
|
@ -156,14 +155,14 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
{
|
{
|
||||||
if( dictionary_size == 65535 && match_len_limit == 16 )
|
if( dictionary_size == 65535 && match_len_limit == 16 )
|
||||||
{
|
{
|
||||||
e->flz_encoder = (struct FLZ_encoder *)malloc( sizeof (struct FLZ_encoder) );
|
e->flz_encoder = (FLZ_encoder *)malloc( sizeof (FLZ_encoder) );
|
||||||
if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) )
|
if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) )
|
||||||
{ e->lz_encoder_base = &e->flz_encoder->eb; return e; }
|
{ e->lz_encoder_base = &e->flz_encoder->eb; return e; }
|
||||||
free( e->flz_encoder ); e->flz_encoder = 0;
|
free( e->flz_encoder ); e->flz_encoder = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e->lz_encoder = (struct LZ_encoder *)malloc( sizeof (struct LZ_encoder) );
|
e->lz_encoder = (LZ_encoder *)malloc( sizeof (LZ_encoder) );
|
||||||
if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ),
|
if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ),
|
||||||
match_len_limit, member_size ) )
|
match_len_limit, member_size ) )
|
||||||
{ e->lz_encoder_base = &e->lz_encoder->eb; return e; }
|
{ e->lz_encoder_base = &e->lz_encoder->eb; return e; }
|
||||||
|
@ -176,7 +175,7 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_close( struct LZ_Encoder * const e )
|
int LZ_compress_close( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return -1;
|
if( !e ) return -1;
|
||||||
if( e->lz_encoder_base )
|
if( e->lz_encoder_base )
|
||||||
|
@ -187,7 +186,7 @@ int LZ_compress_close( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_finish( struct LZ_Encoder * const e )
|
int LZ_compress_finish( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
Mb_finish( &e->lz_encoder_base->mb );
|
Mb_finish( &e->lz_encoder_base->mb );
|
||||||
|
@ -205,7 +204,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
int LZ_compress_restart_member( LZ_Encoder * const e,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
|
@ -224,7 +223,7 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
int LZ_compress_sync_flush( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
if( !e->lz_encoder_base->mb.at_stream_end )
|
if( !e->lz_encoder_base->mb.at_stream_end )
|
||||||
|
@ -233,13 +232,13 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_read( struct LZ_Encoder * const e,
|
int LZ_compress_read( LZ_Encoder * const e,
|
||||||
uint8_t * const buffer, const int size )
|
uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
if( size < 0 ) return 0;
|
if( size < 0 ) return 0;
|
||||||
|
|
||||||
{ struct LZ_encoder_base * const eb = e->lz_encoder_base;
|
{ LZ_encoder_base * const eb = e->lz_encoder_base;
|
||||||
int out_size = Re_read_data( &eb->renc, buffer, size );
|
int out_size = Re_read_data( &eb->renc, buffer, size );
|
||||||
/* minimize number of calls to encode_member */
|
/* minimize number of calls to encode_member */
|
||||||
if( out_size < size || size == 0 )
|
if( out_size < size || size == 0 )
|
||||||
|
@ -255,7 +254,7 @@ int LZ_compress_read( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_write( struct LZ_Encoder * const e,
|
int LZ_compress_write( LZ_Encoder * const e,
|
||||||
const uint8_t * const buffer, const int size )
|
const uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
|
@ -263,21 +262,21 @@ int LZ_compress_write( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_write_size( struct LZ_Encoder * const e )
|
int LZ_compress_write_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
return Mb_free_bytes( &e->lz_encoder_base->mb );
|
return Mb_free_bytes( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const e )
|
LZ_Errno LZ_compress_errno( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return LZ_bad_argument;
|
if( !e ) return LZ_bad_argument;
|
||||||
return e->lz_errno;
|
return e->lz_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_finished( struct LZ_Encoder * const e )
|
int LZ_compress_finished( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return -1;
|
if( !check_encoder( e ) ) return -1;
|
||||||
return Mb_data_finished( &e->lz_encoder_base->mb ) &&
|
return Mb_data_finished( &e->lz_encoder_base->mb ) &&
|
||||||
|
@ -285,35 +284,35 @@ int LZ_compress_finished( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_member_finished( struct LZ_Encoder * const e )
|
int LZ_compress_member_finished( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return -1;
|
if( !check_encoder( e ) ) return -1;
|
||||||
return LZeb_member_finished( e->lz_encoder_base );
|
return LZeb_member_finished( e->lz_encoder_base );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_data_position( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_data_position( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return Mb_data_position( &e->lz_encoder_base->mb );
|
return Mb_data_position( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_member_position( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_member_position( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return Re_member_position( &e->lz_encoder_base->renc );
|
return Re_member_position( &e->lz_encoder_base->renc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_total_in_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb );
|
return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_total_out_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
|
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
|
||||||
|
@ -322,14 +321,13 @@ unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
|
||||||
|
|
||||||
/* -------------------- Decompression Functions -------------------- */
|
/* -------------------- Decompression Functions -------------------- */
|
||||||
|
|
||||||
struct LZ_Decoder * LZ_decompress_open( void )
|
LZ_Decoder * LZ_decompress_open( void )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const d =
|
LZ_Decoder * const d = (LZ_Decoder *)malloc( sizeof (LZ_Decoder) );
|
||||||
(struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) );
|
|
||||||
if( !d ) return 0;
|
if( !d ) return 0;
|
||||||
LZ_Decoder_init( d );
|
LZ_Decoder_init( d );
|
||||||
|
|
||||||
d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) );
|
d->rdec = (Range_decoder *)malloc( sizeof (Range_decoder) );
|
||||||
if( !d->rdec || !Rd_init( d->rdec ) )
|
if( !d->rdec || !Rd_init( d->rdec ) )
|
||||||
{
|
{
|
||||||
if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; }
|
if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; }
|
||||||
|
@ -339,7 +337,7 @@ struct LZ_Decoder * LZ_decompress_open( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_close( struct LZ_Decoder * const d )
|
int LZ_decompress_close( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return -1;
|
if( !d ) return -1;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
@ -350,7 +348,7 @@ int LZ_decompress_close( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_finish( struct LZ_Decoder * const d )
|
int LZ_decompress_finish( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
if( d->seeking )
|
if( d->seeking )
|
||||||
|
@ -360,7 +358,7 @@ int LZ_decompress_finish( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_reset( struct LZ_Decoder * const d )
|
int LZ_decompress_reset( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
@ -376,7 +374,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
int LZ_decompress_sync_to_member( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
unsigned skipped = 0;
|
unsigned skipped = 0;
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
|
@ -395,7 +393,7 @@ int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_read( struct LZ_Decoder * const d,
|
int LZ_decompress_read( LZ_Decoder * const d,
|
||||||
uint8_t * const buffer, const int size )
|
uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -467,7 +465,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d,
|
||||||
d->fatal = true;
|
d->fatal = true;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
d->lz_decoder = (struct LZ_decoder *)malloc( sizeof (struct LZ_decoder) );
|
d->lz_decoder = (LZ_decoder *)malloc( sizeof (LZ_decoder) );
|
||||||
if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec,
|
if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec,
|
||||||
Lh_get_dictionary_size( d->member_header ) ) )
|
Lh_get_dictionary_size( d->member_header ) ) )
|
||||||
{ /* not enough free memory */
|
{ /* not enough free memory */
|
||||||
|
@ -486,7 +484,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d,
|
||||||
{ d->rdec->member_position += Cb_used_bytes( &d->rdec->cb );
|
{ d->rdec->member_position += Cb_used_bytes( &d->rdec->cb );
|
||||||
Cb_reset( &d->rdec->cb );
|
Cb_reset( &d->rdec->cb );
|
||||||
d->lz_errno = LZ_unexpected_eof; }
|
d->lz_errno = LZ_unexpected_eof; }
|
||||||
else if( result == 5 ) d->lz_errno = LZ_library_error;
|
else if( result == 6 ) d->lz_errno = LZ_library_error;
|
||||||
else d->lz_errno = LZ_data_error;
|
else d->lz_errno = LZ_data_error;
|
||||||
d->fatal = true;
|
d->fatal = true;
|
||||||
if( Cb_empty( &d->lz_decoder->cb ) ) return -1;
|
if( Cb_empty( &d->lz_decoder->cb ) ) return -1;
|
||||||
|
@ -496,7 +494,7 @@ get_data:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_write( struct LZ_Decoder * const d,
|
int LZ_decompress_write( LZ_Decoder * const d,
|
||||||
const uint8_t * const buffer, const int size )
|
const uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -519,21 +517,21 @@ int LZ_decompress_write( struct LZ_Decoder * const d,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_write_size( struct LZ_Decoder * const d )
|
int LZ_decompress_write_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return Rd_free_bytes( d->rdec );
|
return Rd_free_bytes( d->rdec );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d )
|
LZ_Errno LZ_decompress_errno( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return LZ_bad_argument;
|
if( !d ) return LZ_bad_argument;
|
||||||
return d->lz_errno;
|
return d->lz_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_finished( struct LZ_Decoder * const d )
|
int LZ_decompress_finished( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return Rd_finished( d->rdec ) &&
|
return Rd_finished( d->rdec ) &&
|
||||||
|
@ -541,28 +539,28 @@ int LZ_decompress_finished( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_member_finished( struct LZ_Decoder * const d )
|
int LZ_decompress_member_finished( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return d->lz_decoder && LZd_member_finished( d->lz_decoder );
|
return d->lz_decoder && LZd_member_finished( d->lz_decoder );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_member_version( struct LZ_Decoder * const d )
|
int LZ_decompress_member_version( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
return Lh_version( d->member_header );
|
return Lh_version( d->member_header );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_dictionary_size( struct LZ_Decoder * const d )
|
int LZ_decompress_dictionary_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
return Lh_get_dictionary_size( d->member_header );
|
return Lh_get_dictionary_size( d->member_header );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
unsigned LZ_decompress_data_crc( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( check_decoder( d ) && d->lz_decoder )
|
if( check_decoder( d ) && d->lz_decoder )
|
||||||
return LZd_crc( d->lz_decoder );
|
return LZd_crc( d->lz_decoder );
|
||||||
|
@ -570,7 +568,7 @@ unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_data_position( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( check_decoder( d ) && d->lz_decoder )
|
if( check_decoder( d ) && d->lz_decoder )
|
||||||
return LZd_data_position( d->lz_decoder );
|
return LZd_data_position( d->lz_decoder );
|
||||||
|
@ -578,21 +576,21 @@ unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_member_position( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
return d->rdec->member_position;
|
return d->rdec->member_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
return d->partial_in_size + d->rdec->member_position;
|
return d->partial_in_size + d->rdec->member_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
|
81
lzlib.h
81
lzlib.h
|
@ -1,5 +1,5 @@
|
||||||
/* Lzlib - Compression library for the lzip format
|
/* Lzlib - Compression library for the lzip format
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software. Redistribution and use in source and
|
This library is free software. Redistribution and use in source and
|
||||||
binary forms, with or without modification, are permitted provided
|
binary forms, with or without modification, are permitted provided
|
||||||
|
@ -26,16 +26,17 @@ extern "C" {
|
||||||
|
|
||||||
#define LZ_API_VERSION 1015
|
#define LZ_API_VERSION 1015
|
||||||
|
|
||||||
static const char * const LZ_version_string = "1.15-pre1";
|
static const char * const LZ_version_string = "1.15";
|
||||||
|
|
||||||
enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error,
|
typedef enum LZ_Errno
|
||||||
|
{ LZ_ok = 0, LZ_bad_argument, LZ_mem_error,
|
||||||
LZ_sequence_error, LZ_header_error, LZ_unexpected_eof,
|
LZ_sequence_error, LZ_header_error, LZ_unexpected_eof,
|
||||||
LZ_data_error, LZ_library_error };
|
LZ_data_error, LZ_library_error } LZ_Errno;
|
||||||
|
|
||||||
|
|
||||||
int LZ_api_version( void ); /* new in 1.12 */
|
int LZ_api_version( void ); /* new in 1.12 */
|
||||||
const char * LZ_version( void );
|
const char * LZ_version( void );
|
||||||
const char * LZ_strerror( const enum LZ_Errno lz_errno );
|
const char * LZ_strerror( const LZ_Errno lz_errno );
|
||||||
|
|
||||||
int LZ_min_dictionary_bits( void );
|
int LZ_min_dictionary_bits( void );
|
||||||
int LZ_min_dictionary_size( void );
|
int LZ_min_dictionary_size( void );
|
||||||
|
@ -47,63 +48,63 @@ int LZ_max_match_len_limit( void );
|
||||||
|
|
||||||
/* --------------------- Compression Functions --------------------- */
|
/* --------------------- Compression Functions --------------------- */
|
||||||
|
|
||||||
struct LZ_Encoder;
|
typedef struct LZ_Encoder LZ_Encoder;
|
||||||
|
|
||||||
struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
const int match_len_limit,
|
const int match_len_limit,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
int LZ_compress_close( struct LZ_Encoder * const encoder );
|
int LZ_compress_close( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
int LZ_compress_finish( struct LZ_Encoder * const encoder );
|
int LZ_compress_finish( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_restart_member( struct LZ_Encoder * const encoder,
|
int LZ_compress_restart_member( LZ_Encoder * const encoder,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
int LZ_compress_sync_flush( struct LZ_Encoder * const encoder );
|
int LZ_compress_sync_flush( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
int LZ_compress_read( struct LZ_Encoder * const encoder,
|
int LZ_compress_read( LZ_Encoder * const encoder,
|
||||||
uint8_t * const buffer, const int size );
|
uint8_t * const buffer, const int size );
|
||||||
int LZ_compress_write( struct LZ_Encoder * const encoder,
|
int LZ_compress_write( LZ_Encoder * const encoder,
|
||||||
const uint8_t * const buffer, const int size );
|
const uint8_t * const buffer, const int size );
|
||||||
int LZ_compress_write_size( struct LZ_Encoder * const encoder );
|
int LZ_compress_write_size( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const encoder );
|
LZ_Errno LZ_compress_errno( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_finished( struct LZ_Encoder * const encoder );
|
int LZ_compress_finished( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_member_finished( struct LZ_Encoder * const encoder );
|
int LZ_compress_member_finished( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
unsigned long long LZ_compress_data_position( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_data_position( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_member_position( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_member_position( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_total_in_size( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_total_out_size( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
|
|
||||||
/* -------------------- Decompression Functions -------------------- */
|
/* -------------------- Decompression Functions -------------------- */
|
||||||
|
|
||||||
struct LZ_Decoder;
|
typedef struct LZ_Decoder LZ_Decoder;
|
||||||
|
|
||||||
struct LZ_Decoder * LZ_decompress_open( void );
|
LZ_Decoder * LZ_decompress_open( void );
|
||||||
int LZ_decompress_close( struct LZ_Decoder * const decoder );
|
int LZ_decompress_close( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_finish( struct LZ_Decoder * const decoder );
|
int LZ_decompress_finish( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_reset( struct LZ_Decoder * const decoder );
|
int LZ_decompress_reset( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_sync_to_member( struct LZ_Decoder * const decoder );
|
int LZ_decompress_sync_to_member( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_read( struct LZ_Decoder * const decoder,
|
int LZ_decompress_read( LZ_Decoder * const decoder,
|
||||||
uint8_t * const buffer, const int size );
|
uint8_t * const buffer, const int size );
|
||||||
int LZ_decompress_write( struct LZ_Decoder * const decoder,
|
int LZ_decompress_write( LZ_Decoder * const decoder,
|
||||||
const uint8_t * const buffer, const int size );
|
const uint8_t * const buffer, const int size );
|
||||||
int LZ_decompress_write_size( struct LZ_Decoder * const decoder );
|
int LZ_decompress_write_size( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const decoder );
|
LZ_Errno LZ_decompress_errno( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_finished( struct LZ_Decoder * const decoder );
|
int LZ_decompress_finished( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_member_finished( struct LZ_Decoder * const decoder );
|
int LZ_decompress_member_finished( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_member_version( struct LZ_Decoder * const decoder );
|
int LZ_decompress_member_version( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_dictionary_size( struct LZ_Decoder * const decoder );
|
int LZ_decompress_dictionary_size( LZ_Decoder * const decoder );
|
||||||
unsigned LZ_decompress_data_crc( struct LZ_Decoder * const decoder );
|
unsigned LZ_decompress_data_crc( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_data_position( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_member_position( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
134
minilzip.c
134
minilzip.c
|
@ -1,5 +1,5 @@
|
||||||
/* Minilzip - Test program for the library lzlib
|
/* Minilzip - Test program for the library lzlib
|
||||||
Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -91,7 +91,7 @@ static const char * const mem_msg = "Not enough memory.";
|
||||||
int verbosity = 0;
|
int verbosity = 0;
|
||||||
|
|
||||||
static const char * const program_name = "minilzip";
|
static const char * const program_name = "minilzip";
|
||||||
static const char * const program_year = "2024";
|
static const char * const program_year = "2025";
|
||||||
static const char * invocation_name = "minilzip"; /* default value */
|
static const char * invocation_name = "minilzip"; /* default value */
|
||||||
|
|
||||||
static const struct { const char * from; const char * to; } known_extensions[] = {
|
static const struct { const char * from; const char * to; } known_extensions[] = {
|
||||||
|
@ -99,13 +99,13 @@ static const struct { const char * from; const char * to; } known_extensions[] =
|
||||||
{ ".tlz", ".tar" },
|
{ ".tlz", ".tar" },
|
||||||
{ 0, 0 } };
|
{ 0, 0 } };
|
||||||
|
|
||||||
struct Lzma_options
|
typedef struct Lzma_options
|
||||||
{
|
{
|
||||||
int dictionary_size; /* 4 KiB .. 512 MiB */
|
int dictionary_size; /* 4 KiB .. 512 MiB */
|
||||||
int match_len_limit; /* 5 .. 273 */
|
int match_len_limit; /* 5 .. 273 */
|
||||||
};
|
} Lzma_options;
|
||||||
|
|
||||||
enum Mode { m_compress, m_decompress, m_test };
|
typedef enum Mode { m_compress, m_decompress, m_test } Mode;
|
||||||
|
|
||||||
/* Variables used in signal handler context.
|
/* Variables used in signal handler context.
|
||||||
They are not declared volatile because the handler never returns. */
|
They are not declared volatile because the handler never returns. */
|
||||||
|
@ -116,25 +116,26 @@ static bool delete_output_on_interrupt = false;
|
||||||
|
|
||||||
static void show_help( void )
|
static void show_help( void )
|
||||||
{
|
{
|
||||||
printf( "Minilzip is a test program for the compression library lzlib, compatible\n"
|
printf( "Minilzip is a test program for the compression library lzlib. Minilzip is\n"
|
||||||
"(interoperable) with lzip 1.4 or newer.\n"
|
"not intended to be installed because lzip has more features, but minilzip is\n"
|
||||||
|
"well tested and you can use it as your main compressor if so you wish.\n"
|
||||||
"\nLzip is a lossless data compressor with a user interface similar to the one\n"
|
"\nLzip is a lossless data compressor with a user interface similar to the one\n"
|
||||||
"of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n"
|
"of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov\n"
|
||||||
"chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n"
|
"chain-Algorithm) designed to achieve complete interoperability between\n"
|
||||||
"maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n"
|
"implementations. The maximum dictionary size is 512 MiB so that any lzip\n"
|
||||||
"on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n"
|
"file can be decompressed on 32-bit machines. Lzip provides accurate and\n"
|
||||||
"checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n"
|
"robust 3-factor integrity checking. 'lzip -0' compresses about as fast as\n"
|
||||||
"files more than bzip2 (lzip -9). Decompression speed is intermediate between\n"
|
"gzip, while 'lzip -9' compresses most files more than bzip2. Decompression\n"
|
||||||
"gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery\n"
|
"speed is intermediate between gzip and bzip2. Lzip provides better data\n"
|
||||||
"perspective. Lzip has been designed, written, and tested with great care to\n"
|
"recovery capabilities than gzip and bzip2. Lzip has been designed, written,\n"
|
||||||
"replace gzip and bzip2 as the standard general-purpose compressed format for\n"
|
"and tested with great care to replace gzip and bzip2 as general-purpose\n"
|
||||||
"Unix-like systems.\n"
|
"compressed format for Unix-like systems.\n"
|
||||||
"\nUsage: %s [options] [files]\n", invocation_name );
|
"\nUsage: %s [options] [files]\n", invocation_name );
|
||||||
printf( "\nOptions:\n"
|
printf( "\nOptions:\n"
|
||||||
" -h, --help display this help and exit\n"
|
" -h, --help display this help and exit\n"
|
||||||
" -V, --version output version information and exit\n"
|
" -V, --version output version information and exit\n"
|
||||||
" -a, --trailing-error exit with error status if trailing data\n"
|
" -a, --trailing-error exit with error status if trailing data\n"
|
||||||
" -b, --member-size=<bytes> set member size limit in bytes\n"
|
" -b, --member-size=<bytes> set member size limit of multimember files\n"
|
||||||
" -c, --stdout write to standard output, keep input files\n"
|
" -c, --stdout write to standard output, keep input files\n"
|
||||||
" -d, --decompress decompress, test compressed file integrity\n"
|
" -d, --decompress decompress, test compressed file integrity\n"
|
||||||
" -f, --force overwrite existing output files\n"
|
" -f, --force overwrite existing output files\n"
|
||||||
|
@ -264,16 +265,16 @@ static void * resize_buffer( void * buf, const unsigned min_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Pretty_print
|
typedef struct Pretty_print
|
||||||
{
|
{
|
||||||
const char * name;
|
const char * name;
|
||||||
char * padded_name;
|
char * padded_name;
|
||||||
const char * stdin_name;
|
const char * stdin_name;
|
||||||
unsigned longest_name;
|
unsigned longest_name;
|
||||||
bool first_post;
|
bool first_post;
|
||||||
};
|
} Pretty_print;
|
||||||
|
|
||||||
static void Pp_init( struct Pretty_print * const pp,
|
static void Pp_init( Pretty_print * const pp,
|
||||||
const char * const filenames[], const int num_filenames )
|
const char * const filenames[], const int num_filenames )
|
||||||
{
|
{
|
||||||
pp->name = 0;
|
pp->name = 0;
|
||||||
|
@ -294,11 +295,10 @@ static void Pp_init( struct Pretty_print * const pp,
|
||||||
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pp_free( struct Pretty_print * const pp )
|
void Pp_free( Pretty_print * const pp )
|
||||||
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
|
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
|
||||||
|
|
||||||
static void Pp_set_name( struct Pretty_print * const pp,
|
static void Pp_set_name( Pretty_print * const pp, const char * const filename )
|
||||||
const char * const filename )
|
|
||||||
{
|
{
|
||||||
unsigned name_len, padded_name_len, i = 0;
|
unsigned name_len, padded_name_len, i = 0;
|
||||||
|
|
||||||
|
@ -316,10 +316,10 @@ static void Pp_set_name( struct Pretty_print * const pp,
|
||||||
pp->first_post = true;
|
pp->first_post = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Pp_reset( struct Pretty_print * const pp )
|
static void Pp_reset( Pretty_print * const pp )
|
||||||
{ if( pp->name && pp->name[0] ) pp->first_post = true; }
|
{ if( pp->name && pp->name[0] ) pp->first_post = true; }
|
||||||
|
|
||||||
static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
|
static void Pp_show_msg( Pretty_print * const pp, const char * const msg )
|
||||||
{
|
{
|
||||||
if( verbosity < 0 ) return;
|
if( verbosity < 0 ) return;
|
||||||
if( pp->first_post )
|
if( pp->first_post )
|
||||||
|
@ -339,7 +339,7 @@ static void show_header( const unsigned dictionary_size )
|
||||||
const char * p = "";
|
const char * p = "";
|
||||||
const char * np = " ";
|
const char * np = " ";
|
||||||
unsigned num = dictionary_size;
|
unsigned num = dictionary_size;
|
||||||
bool exact = ( num % factor == 0 );
|
bool exact = num % factor == 0;
|
||||||
|
|
||||||
int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
||||||
{ num /= factor; if( num % factor != 0 ) exact = false;
|
{ num /= factor; if( num % factor != 0 ) exact = false;
|
||||||
|
@ -360,7 +360,7 @@ static const char * format_num3( unsigned long long num )
|
||||||
char * const buf = buffer[current++]; current %= buffers;
|
char * const buf = buffer[current++]; current %= buffers;
|
||||||
char * p = buf + bufsize - 1; /* fill the buffer backwards */
|
char * p = buf + bufsize - 1; /* fill the buffer backwards */
|
||||||
*p = 0; /* terminator */
|
*p = 0; /* terminator */
|
||||||
if( num > 1024 )
|
if( num > 9999 )
|
||||||
{
|
{
|
||||||
char prefix = 0; /* try binary first, then si */
|
char prefix = 0; /* try binary first, then si */
|
||||||
for( i = 0; i < n && num != 0 && num % 1024 == 0; ++i )
|
for( i = 0; i < n && num != 0 && num % 1024 == 0; ++i )
|
||||||
|
@ -459,7 +459,7 @@ static int get_dict_size( const char * const arg, const char * const option_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void set_mode( enum Mode * const program_modep, const enum Mode new_mode )
|
static void set_mode( Mode * const program_modep, const Mode new_mode )
|
||||||
{
|
{
|
||||||
if( *program_modep != m_compress && *program_modep != new_mode )
|
if( *program_modep != m_compress && *program_modep != new_mode )
|
||||||
{
|
{
|
||||||
|
@ -524,13 +524,13 @@ static void set_d_outname( const char * const name, const int eindex )
|
||||||
|
|
||||||
|
|
||||||
static int open_instream( const char * const name, struct stat * const in_statsp,
|
static int open_instream( const char * const name, struct stat * const in_statsp,
|
||||||
const enum Mode program_mode, const int eindex,
|
const Mode program_mode, const int eindex,
|
||||||
const bool one_to_one, const bool recompress )
|
const bool one_to_one, const bool recompress )
|
||||||
{
|
{
|
||||||
if( program_mode == m_compress && !recompress && eindex >= 0 )
|
if( program_mode == m_compress && !recompress && eindex >= 0 )
|
||||||
{
|
{
|
||||||
if( verbosity >= 0 )
|
if( verbosity >= 0 )
|
||||||
fprintf( stderr, "%s: %s: Input file already has '%s' suffix.\n",
|
fprintf( stderr, "%s: %s: Input file already has '%s' suffix, ignored.\n",
|
||||||
program_name, name, known_extensions[eindex].from );
|
program_name, name, known_extensions[eindex].from );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -541,9 +541,9 @@ static int open_instream( const char * const name, struct stat * const in_statsp
|
||||||
{
|
{
|
||||||
const int i = fstat( infd, in_statsp );
|
const int i = fstat( infd, in_statsp );
|
||||||
const mode_t mode = in_statsp->st_mode;
|
const mode_t mode = in_statsp->st_mode;
|
||||||
const bool can_read = ( i == 0 &&
|
const bool can_read = i == 0 &&
|
||||||
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
||||||
S_ISFIFO( mode ) || S_ISSOCK( mode ) ) );
|
S_ISFIFO( mode ) || S_ISSOCK( mode ) );
|
||||||
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
|
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
|
||||||
{
|
{
|
||||||
if( verbosity >= 0 )
|
if( verbosity >= 0 )
|
||||||
|
@ -609,7 +609,7 @@ static void signal_handler( int sig )
|
||||||
|
|
||||||
|
|
||||||
static bool check_tty_in( const char * const input_filename, const int infd,
|
static bool check_tty_in( const char * const input_filename, const int infd,
|
||||||
const enum Mode program_mode, int * const retval )
|
const Mode program_mode, int * const retval )
|
||||||
{
|
{
|
||||||
if( ( program_mode == m_decompress || program_mode == m_test ) &&
|
if( ( program_mode == m_decompress || program_mode == m_test ) &&
|
||||||
isatty( infd ) ) /* for example /dev/tty */
|
isatty( infd ) ) /* for example /dev/tty */
|
||||||
|
@ -621,7 +621,7 @@ static bool check_tty_in( const char * const input_filename, const int infd,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_tty_out( const enum Mode program_mode )
|
static bool check_tty_out( const Mode program_mode )
|
||||||
{
|
{
|
||||||
if( program_mode == m_compress && isatty( outfd ) )
|
if( program_mode == m_compress && isatty( outfd ) )
|
||||||
{ show_file_error( output_filename[0] ?
|
{ show_file_error( output_filename[0] ?
|
||||||
|
@ -717,10 +717,10 @@ static bool next_filename( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_compress( struct LZ_Encoder * const encoder,
|
static int do_compress( LZ_Encoder * const encoder,
|
||||||
const unsigned long long member_size,
|
const unsigned long long member_size,
|
||||||
const unsigned long long volume_size, const int infd,
|
const unsigned long long volume_size, const int infd,
|
||||||
struct Pretty_print * const pp,
|
Pretty_print * const pp,
|
||||||
const struct stat * const in_statsp )
|
const struct stat * const in_statsp )
|
||||||
{
|
{
|
||||||
unsigned long long partial_volume_size = 0;
|
unsigned long long partial_volume_size = 0;
|
||||||
|
@ -819,11 +819,11 @@ static int do_compress( struct LZ_Encoder * const encoder,
|
||||||
|
|
||||||
static int compress( const unsigned long long member_size,
|
static int compress( const unsigned long long member_size,
|
||||||
const unsigned long long volume_size, const int infd,
|
const unsigned long long volume_size, const int infd,
|
||||||
const struct Lzma_options * const encoder_options,
|
const Lzma_options * const encoder_options,
|
||||||
struct Pretty_print * const pp,
|
Pretty_print * const pp,
|
||||||
const struct stat * const in_statsp )
|
const struct stat * const in_statsp )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( encoder_options->dictionary_size,
|
LZ_compress_open( encoder_options->dictionary_size,
|
||||||
encoder_options->match_len_limit, ( volume_size > 0 ) ?
|
encoder_options->match_len_limit, ( volume_size > 0 ) ?
|
||||||
min( member_size, volume_size ) : member_size );
|
min( member_size, volume_size ) : member_size );
|
||||||
|
@ -844,14 +844,16 @@ static int compress( const unsigned long long member_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
static int do_decompress( LZ_Decoder * const decoder, const int infd,
|
||||||
struct Pretty_print * const pp, const bool ignore_trailing,
|
Pretty_print * const pp, const bool from_stdin,
|
||||||
const bool loose_trailing, const bool testing )
|
const bool ignore_trailing, const bool loose_trailing,
|
||||||
|
const bool testing )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 65536 };
|
enum { buffer_size = 65536 };
|
||||||
uint8_t buffer[buffer_size]; /* read/write buffer */
|
uint8_t buffer[buffer_size]; /* read/write buffer */
|
||||||
unsigned long long total_in = 0; /* to detect library stall */
|
unsigned long long total_in = 0; /* to detect library stall */
|
||||||
bool first_member;
|
bool first_member;
|
||||||
|
bool empty = false, multi = false;
|
||||||
|
|
||||||
for( first_member = true; ; )
|
for( first_member = true; ; )
|
||||||
{
|
{
|
||||||
|
@ -890,10 +892,13 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
else if( rd < 0 ) { out_size = rd; break; }
|
else if( rd < 0 ) { out_size = rd; break; }
|
||||||
if( LZ_decompress_member_finished( decoder ) == 1 )
|
if( LZ_decompress_member_finished( decoder ) == 1 )
|
||||||
{
|
{
|
||||||
|
const unsigned long long data_size = LZ_decompress_data_position( decoder );
|
||||||
|
if( !from_stdin )
|
||||||
|
{ multi = !first_member; if( data_size == 0 ) empty = true; }
|
||||||
if( verbosity >= 1 )
|
if( verbosity >= 1 )
|
||||||
{
|
{
|
||||||
const unsigned long long data_size = LZ_decompress_data_position( decoder );
|
const unsigned long long member_size =
|
||||||
const unsigned long long member_size = LZ_decompress_member_position( decoder );
|
LZ_decompress_member_position( decoder );
|
||||||
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
||||||
Pp_show_msg( pp, 0 );
|
Pp_show_msg( pp, 0 );
|
||||||
if( verbosity >= 2 )
|
if( verbosity >= 2 )
|
||||||
|
@ -921,7 +926,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
if( out_size < 0 || ( first_member && out_size == 0 ) )
|
if( out_size < 0 || ( first_member && out_size == 0 ) )
|
||||||
{
|
{
|
||||||
const unsigned long long member_pos = LZ_decompress_member_position( decoder );
|
const unsigned long long member_pos = LZ_decompress_member_position( decoder );
|
||||||
const enum LZ_Errno lz_errno = LZ_decompress_errno( decoder );
|
const LZ_Errno lz_errno = LZ_decompress_errno( decoder );
|
||||||
if( lz_errno == LZ_library_error )
|
if( lz_errno == LZ_library_error )
|
||||||
internal_error( "library error (LZ_decompress_read)." );
|
internal_error( "library error (LZ_decompress_read)." );
|
||||||
if( member_pos <= 6 )
|
if( member_pos <= 6 )
|
||||||
|
@ -943,6 +948,8 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
LZ_decompress_member_version( decoder ) ); } }
|
LZ_decompress_member_version( decoder ) ); } }
|
||||||
else if( member_pos == 5 )
|
else if( member_pos == 5 )
|
||||||
Pp_show_msg( pp, "Invalid dictionary size in member header." );
|
Pp_show_msg( pp, "Invalid dictionary size in member header." );
|
||||||
|
else if( member_pos == 6 )
|
||||||
|
Pp_show_msg( pp, "Nonzero first LZMA byte." );
|
||||||
else if( first_member ) /* for lzlib older than 1.10 */
|
else if( first_member ) /* for lzlib older than 1.10 */
|
||||||
Pp_show_msg( pp, "Bad version or dictionary size in member header." );
|
Pp_show_msg( pp, "Bad version or dictionary size in member header." );
|
||||||
else if( !loose_trailing )
|
else if( !loose_trailing )
|
||||||
|
@ -982,20 +989,22 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr );
|
if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr );
|
||||||
|
if( empty && multi )
|
||||||
|
{ show_file_error( pp->name, "Empty member not allowed.", 0 ); return 2; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int decompress( const int infd, struct Pretty_print * const pp,
|
static int decompress( const int infd, Pretty_print * const pp,
|
||||||
const bool ignore_trailing,
|
const bool from_stdin, const bool ignore_trailing,
|
||||||
const bool loose_trailing, const bool testing )
|
const bool loose_trailing, const bool testing )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
{ Pp_show_msg( pp, mem_msg ); retval = 1; }
|
{ Pp_show_msg( pp, mem_msg ); retval = 1; }
|
||||||
else retval = do_decompress( decoder, infd, pp, ignore_trailing,
|
else retval = do_decompress( decoder, infd, pp, from_stdin, ignore_trailing,
|
||||||
loose_trailing, testing );
|
loose_trailing, testing );
|
||||||
LZ_decompress_close( decoder );
|
LZ_decompress_close( decoder );
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -1038,7 +1047,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
||||||
corresponding LZMA compression parameters. */
|
corresponding LZMA compression parameters. */
|
||||||
const struct Lzma_options option_mapping[] =
|
const Lzma_options option_mapping[] =
|
||||||
{
|
{
|
||||||
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
||||||
{ 1 << 20, 5 }, /* -1 */
|
{ 1 << 20, 5 }, /* -1 */
|
||||||
|
@ -1050,14 +1059,13 @@ int main( const int argc, const char * const argv[] )
|
||||||
{ 1 << 24, 68 }, /* -7 */
|
{ 1 << 24, 68 }, /* -7 */
|
||||||
{ 3 << 23, 132 }, /* -8 */
|
{ 3 << 23, 132 }, /* -8 */
|
||||||
{ 1 << 25, 273 } }; /* -9 */
|
{ 1 << 25, 273 } }; /* -9 */
|
||||||
struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
|
Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
|
||||||
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
||||||
const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */
|
const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */
|
||||||
unsigned long long member_size = max_member_size;
|
unsigned long long member_size = max_member_size;
|
||||||
unsigned long long volume_size = 0;
|
unsigned long long volume_size = 0;
|
||||||
const char * default_output_filename = "";
|
const char * default_output_filename = "";
|
||||||
enum Mode program_mode = m_compress;
|
Mode program_mode = m_compress;
|
||||||
int i;
|
|
||||||
bool force = false;
|
bool force = false;
|
||||||
bool ignore_trailing = true;
|
bool ignore_trailing = true;
|
||||||
bool keep_input_files = false;
|
bool keep_input_files = false;
|
||||||
|
@ -1067,7 +1075,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
if( argc > 0 ) invocation_name = argv[0];
|
if( argc > 0 ) invocation_name = argv[0];
|
||||||
|
|
||||||
enum { opt_chk = 256, opt_lt };
|
enum { opt_chk = 256, opt_lt };
|
||||||
const struct ap_Option options[] =
|
const ap_Option options[] =
|
||||||
{
|
{
|
||||||
{ '0', "fast", ap_no },
|
{ '0', "fast", ap_no },
|
||||||
{ '1', 0, ap_no },
|
{ '1', 0, ap_no },
|
||||||
|
@ -1101,7 +1109,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{ 0, 0, ap_no } };
|
{ 0, 0, ap_no } };
|
||||||
|
|
||||||
/* static because valgrind complains and memory management in C sucks */
|
/* static because valgrind complains and memory management in C sucks */
|
||||||
static struct Arg_parser parser;
|
static Arg_parser parser;
|
||||||
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
||||||
{ show_error( mem_msg, 0, false ); return 1; }
|
{ show_error( mem_msg, 0, false ); return 1; }
|
||||||
if( ap_error( &parser ) ) /* bad option */
|
if( ap_error( &parser ) ) /* bad option */
|
||||||
|
@ -1116,8 +1124,8 @@ int main( const int argc, const char * const argv[] )
|
||||||
const char * const arg = ap_argument( &parser, argind );
|
const char * const arg = ap_argument( &parser, argind );
|
||||||
switch( code )
|
switch( code )
|
||||||
{
|
{
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '6': case '7': case '8': case '9':
|
||||||
encoder_options = option_mapping[code-'0']; break;
|
encoder_options = option_mapping[code-'0']; break;
|
||||||
case 'a': ignore_trailing = false; break;
|
case 'a': ignore_trailing = false; break;
|
||||||
case 'b': member_size = getnum( arg, pn, 100000, max_member_size ); break;
|
case 'b': member_size = getnum( arg, pn, 100000, max_member_size ); break;
|
||||||
|
@ -1130,7 +1138,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
case 'm': encoder_options.match_len_limit =
|
case 'm': encoder_options.match_len_limit =
|
||||||
getnum( arg, pn, LZ_min_match_len_limit(),
|
getnum( arg, pn, LZ_min_match_len_limit(),
|
||||||
LZ_max_match_len_limit() ); break;
|
LZ_max_match_len_limit() ); break;
|
||||||
case 'n': break;
|
case 'n': break; /* ignored */
|
||||||
case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true;
|
case 'o': if( strcmp( arg, "-" ) == 0 ) to_stdout = true;
|
||||||
else { default_output_filename = arg; } break;
|
else { default_output_filename = arg; } break;
|
||||||
case 'q': verbosity = -1; break;
|
case 'q': verbosity = -1; break;
|
||||||
|
@ -1171,6 +1179,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
|
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
|
||||||
filenames[0] = "-";
|
filenames[0] = "-";
|
||||||
|
|
||||||
|
int i;
|
||||||
bool filenames_given = false;
|
bool filenames_given = false;
|
||||||
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
|
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
|
||||||
{
|
{
|
||||||
|
@ -1200,7 +1209,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) )
|
if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) )
|
||||||
set_signals( signal_handler );
|
set_signals( signal_handler );
|
||||||
|
|
||||||
static struct Pretty_print pp;
|
static Pretty_print pp;
|
||||||
Pp_init( &pp, filenames, num_filenames );
|
Pp_init( &pp, filenames, num_filenames );
|
||||||
|
|
||||||
int failed_tests = 0;
|
int failed_tests = 0;
|
||||||
|
@ -1212,9 +1221,10 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
const char * input_filename = "";
|
const char * input_filename = "";
|
||||||
int infd;
|
int infd;
|
||||||
|
const bool from_stdin = strcmp( filenames[i], "-" ) == 0;
|
||||||
|
|
||||||
Pp_set_name( &pp, filenames[i] );
|
Pp_set_name( &pp, filenames[i] );
|
||||||
if( strcmp( filenames[i], "-" ) == 0 )
|
if( from_stdin )
|
||||||
{
|
{
|
||||||
if( stdin_used ) continue; else stdin_used = true;
|
if( stdin_used ) continue; else stdin_used = true;
|
||||||
infd = STDIN_FILENO;
|
infd = STDIN_FILENO;
|
||||||
|
@ -1260,7 +1270,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
tmp = compress( member_size, volume_size, infd, &encoder_options, &pp,
|
tmp = compress( member_size, volume_size, infd, &encoder_options, &pp,
|
||||||
in_statsp );
|
in_statsp );
|
||||||
else
|
else
|
||||||
tmp = decompress( infd, &pp, ignore_trailing, loose_trailing,
|
tmp = decompress( infd, &pp, from_stdin, ignore_trailing, loose_trailing,
|
||||||
program_mode == m_test );
|
program_mode == m_test );
|
||||||
if( close( infd ) != 0 )
|
if( close( infd ) != 0 )
|
||||||
{ show_file_error( pp.name, "Error closing input file", errno );
|
{ show_file_error( pp.name, "Error closing input file", errno );
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# check script for Lzlib - Compression library for the lzip format
|
# check script for Lzlib - Compression library for the lzip format
|
||||||
# Copyright (C) 2009-2024 Antonio Diaz Diaz.
|
# Copyright (C) 2009-2025 Antonio Diaz Diaz.
|
||||||
#
|
#
|
||||||
# This script is free software: you have unlimited permission
|
# This script is free software: you have unlimited permission
|
||||||
# to copy, distribute, and modify it.
|
# to copy, distribute, and modify it.
|
||||||
|
@ -31,11 +31,11 @@ if [ -d tmp ] ; then rm -rf tmp ; fi
|
||||||
mkdir tmp
|
mkdir tmp
|
||||||
cd "${objdir}"/tmp || framework_failure
|
cd "${objdir}"/tmp || framework_failure
|
||||||
|
|
||||||
cat "${testdir}"/test.txt > in || framework_failure
|
cp "${testdir}"/test.txt in || framework_failure
|
||||||
in_lz="${testdir}"/test.txt.lz
|
in_lz="${testdir}"/test.txt.lz
|
||||||
in_em="${testdir}"/test_em.txt.lz
|
|
||||||
fox_lf="${testdir}"/fox_lf
|
fox_lf="${testdir}"/fox_lf
|
||||||
fox_lz="${testdir}"/fox.lz
|
fox_lz="${testdir}"/fox.lz
|
||||||
|
fnz_lz="${testdir}"/fox_nz.lz
|
||||||
fail=0
|
fail=0
|
||||||
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
|
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ done
|
||||||
"${LZIP}" -q -o out.lz nx_file
|
"${LZIP}" -q -o out.lz nx_file
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
[ ! -e out.lz ] || test_failed $LINENO
|
[ ! -e out.lz ] || test_failed $LINENO
|
||||||
"${LZIP}" -qf -S100k -o out in in
|
"${LZIP}" -qf -S100k -o out in in # only one file with -o and -S
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO
|
{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO
|
||||||
# these are for code coverage
|
# these are for code coverage
|
||||||
|
@ -105,7 +105,7 @@ printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null
|
||||||
|
|
||||||
printf "\ntesting decompression..."
|
printf "\ntesting decompression..."
|
||||||
|
|
||||||
for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do
|
for i in "${in_lz}" "${testdir}"/test_sync.lz ; do
|
||||||
"${LZIP}" -t "$i" || test_failed $LINENO "$i"
|
"${LZIP}" -t "$i" || test_failed $LINENO "$i"
|
||||||
"${LZIP}" -d "$i" -o out || test_failed $LINENO "$i"
|
"${LZIP}" -d "$i" -o out || test_failed $LINENO "$i"
|
||||||
cmp in out || test_failed $LINENO "$i"
|
cmp in out || test_failed $LINENO "$i"
|
||||||
|
@ -118,16 +118,13 @@ for i in "${in_lz}" "${in_em}" "${testdir}"/test_sync.lz ; do
|
||||||
rm -f out || framework_failure
|
rm -f out || framework_failure
|
||||||
done
|
done
|
||||||
|
|
||||||
lines=`"${LZIP}" -tvv "${in_em}" 2>&1 | wc -l` || test_failed $LINENO
|
cp "${in_lz}" out.lz || framework_failure
|
||||||
[ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}"
|
|
||||||
|
|
||||||
cat "${in_lz}" > out.lz || framework_failure
|
|
||||||
"${LZIP}" -dk out.lz || test_failed $LINENO
|
"${LZIP}" -dk out.lz || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
rm -f out || framework_failure
|
rm -f out || framework_failure
|
||||||
"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO
|
"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO
|
||||||
cat fox > copy || framework_failure
|
cp fox copy || framework_failure
|
||||||
cat "${in_lz}" > copy.lz || framework_failure
|
cp "${in_lz}" copy.lz || framework_failure
|
||||||
"${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out
|
"${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
[ ! -e out.lz ] || test_failed $LINENO
|
[ ! -e out.lz ] || test_failed $LINENO
|
||||||
|
@ -138,7 +135,7 @@ cmp in out || test_failed $LINENO
|
||||||
cmp in copy || test_failed $LINENO
|
cmp in copy || test_failed $LINENO
|
||||||
rm -f copy out || framework_failure
|
rm -f copy out || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" > out.lz || framework_failure
|
cp "${in_lz}" out.lz || framework_failure
|
||||||
"${LZIP}" -d -S100k out.lz || test_failed $LINENO # ignore -S
|
"${LZIP}" -d -S100k out.lz || test_failed $LINENO # ignore -S
|
||||||
[ ! -e out.lz ] || test_failed $LINENO
|
[ ! -e out.lz ] || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
|
@ -146,7 +143,6 @@ cmp in out || test_failed $LINENO
|
||||||
printf "to be overwritten" > out || framework_failure
|
printf "to be overwritten" > out || framework_failure
|
||||||
"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
|
"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
rm -f out || framework_failure
|
|
||||||
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
|
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
|
||||||
cmp in ./- || test_failed $LINENO
|
cmp in ./- || test_failed $LINENO
|
||||||
rm -f ./- || framework_failure
|
rm -f ./- || framework_failure
|
||||||
|
@ -154,12 +150,12 @@ rm -f ./- || framework_failure
|
||||||
cmp in ./- || test_failed $LINENO
|
cmp in ./- || test_failed $LINENO
|
||||||
rm -f ./- || framework_failure
|
rm -f ./- || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" > anyothername || framework_failure
|
cp "${in_lz}" anyothername || framework_failure
|
||||||
"${LZIP}" -dv - anyothername - < "${in_lz}" > out 2> /dev/null ||
|
"${LZIP}" -dv - anyothername - < "${in_lz}" > out 2> /dev/null ||
|
||||||
test_failed $LINENO
|
test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
cmp in anyothername.out || test_failed $LINENO
|
cmp in anyothername.out || test_failed $LINENO
|
||||||
rm -f out anyothername.out || framework_failure
|
rm -f anyothername.out || framework_failure
|
||||||
|
|
||||||
"${LZIP}" -tq in "${in_lz}"
|
"${LZIP}" -tq in "${in_lz}"
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
@ -172,7 +168,7 @@ cat out in | cmp in - || test_failed $LINENO # out must be empty
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
rm -f out || framework_failure
|
rm -f out || framework_failure
|
||||||
cat "${in_lz}" > out.lz || framework_failure
|
cp "${in_lz}" out.lz || framework_failure
|
||||||
for i in 1 2 3 4 5 6 7 ; do
|
for i in 1 2 3 4 5 6 7 ; do
|
||||||
printf "g" >> out.lz || framework_failure
|
printf "g" >> out.lz || framework_failure
|
||||||
"${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null
|
"${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null
|
||||||
|
@ -201,6 +197,9 @@ cmp in2 out2 || test_failed $LINENO
|
||||||
rm -f out2 || framework_failure
|
rm -f out2 || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure
|
cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure
|
||||||
|
lines=`"${LZIP}" -tvv out2.lz 2>&1 | wc -l` || test_failed $LINENO
|
||||||
|
[ "${lines}" -eq 2 ] || test_failed $LINENO "${lines}"
|
||||||
|
|
||||||
printf "\ngarbage" >> out2.lz || framework_failure
|
printf "\ngarbage" >> out2.lz || framework_failure
|
||||||
"${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO
|
"${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO
|
||||||
"${LZIP}" -atq out2.lz
|
"${LZIP}" -atq out2.lz
|
||||||
|
@ -218,6 +217,20 @@ printf "to be overwritten" > out2 || framework_failure
|
||||||
cmp in2 out2 || test_failed $LINENO
|
cmp in2 out2 || test_failed $LINENO
|
||||||
rm -f out2 || framework_failure
|
rm -f out2 || framework_failure
|
||||||
|
|
||||||
|
touch empty em || framework_failure
|
||||||
|
"${LZIP}" -0 em || test_failed $LINENO
|
||||||
|
"${LZIP}" -dk em.lz || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
cat em.lz em.lz | "${LZIP}" -t || test_failed $LINENO
|
||||||
|
cat em.lz em.lz | "${LZIP}" -d > em || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
cat em.lz "${in_lz}" | "${LZIP}" -t || test_failed $LINENO
|
||||||
|
cat em.lz "${in_lz}" | "${LZIP}" -d > out || test_failed $LINENO
|
||||||
|
cmp in out || test_failed $LINENO
|
||||||
|
cat "${in_lz}" em.lz | "${LZIP}" -t || test_failed $LINENO
|
||||||
|
cat "${in_lz}" em.lz | "${LZIP}" -d > out || test_failed $LINENO
|
||||||
|
cmp in out || test_failed $LINENO
|
||||||
|
|
||||||
printf "\ntesting compression..."
|
printf "\ntesting compression..."
|
||||||
|
|
||||||
"${LZIP}" -c -0 in in in -S100k -o out3.lz > copy2.lz || test_failed $LINENO
|
"${LZIP}" -c -0 in in in -S100k -o out3.lz > copy2.lz || test_failed $LINENO
|
||||||
|
@ -226,7 +239,7 @@ printf "\ntesting compression..."
|
||||||
"${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO
|
"${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO
|
||||||
[ -e copy2.lz ] || test_failed $LINENO
|
[ -e copy2.lz ] || test_failed $LINENO
|
||||||
cmp in2 out2 || test_failed $LINENO
|
cmp in2 out2 || test_failed $LINENO
|
||||||
rm -f out2 copy2.lz || framework_failure
|
rm -f copy2.lz || framework_failure
|
||||||
|
|
||||||
"${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2
|
"${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
|
@ -293,7 +306,7 @@ rm -f out out.lz00001.lz out.lz00002.lz || framework_failure
|
||||||
"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
|
"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
|
||||||
"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
|
"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
|
||||||
[ ! -e out00003.lz ] || test_failed $LINENO
|
[ ! -e out00003.lz ] || test_failed $LINENO
|
||||||
rm -f out00001.lz || framework_failure
|
rm -f out00001.lz out00002.lz || framework_failure
|
||||||
"${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO
|
"${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO
|
||||||
"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
|
"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
|
||||||
"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
|
"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
|
||||||
|
@ -314,7 +327,8 @@ rm -f in8.lz in8.lz.lz || framework_failure
|
||||||
"${BBEXAMPLE}" "${fox_lf}" || test_failed $LINENO
|
"${BBEXAMPLE}" "${fox_lf}" || test_failed $LINENO
|
||||||
|
|
||||||
"${FFEXAMPLE}" -h > /dev/null || test_failed $LINENO
|
"${FFEXAMPLE}" -h > /dev/null || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" > /dev/null && test_failed $LINENO
|
"${FFEXAMPLE}" > /dev/null
|
||||||
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
rm -f out || framework_failure
|
rm -f out || framework_failure
|
||||||
"${FFEXAMPLE}" -b in out || test_failed $LINENO
|
"${FFEXAMPLE}" -b in out || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
|
@ -322,7 +336,6 @@ cmp in out || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -b in8 | cmp in8 - || test_failed $LINENO
|
"${FFEXAMPLE}" -b in8 | cmp in8 - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -b "${fox_lf}" | cmp "${fox_lf}" - || test_failed $LINENO
|
"${FFEXAMPLE}" -b "${fox_lf}" | cmp "${fox_lf}" - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -d "${in_lz}" - | cmp in - || test_failed $LINENO
|
"${FFEXAMPLE}" -d "${in_lz}" - | cmp in - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -d "${in_em}" - | cmp in - || test_failed $LINENO
|
|
||||||
"${FFEXAMPLE}" -c in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
"${FFEXAMPLE}" -c in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -m in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
"${FFEXAMPLE}" -m in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -l in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
"${FFEXAMPLE}" -l in | "${FFEXAMPLE}" -d | cmp in - || test_failed $LINENO
|
||||||
|
@ -340,11 +353,38 @@ rm -f in8 || framework_failure
|
||||||
|
|
||||||
printf "\ntesting bad input..."
|
printf "\ntesting bad input..."
|
||||||
|
|
||||||
|
cat em.lz em.lz > ee.lz || framework_failure
|
||||||
|
"${LZIP}" -t < ee.lz || test_failed $LINENO
|
||||||
|
"${LZIP}" -d < ee.lz > em || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
"${LZIP}" -tq ee.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -dq ee.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
[ ! -e ee ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -cdq ee.lz > em
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
rm -f empty em || framework_failure
|
||||||
|
cat "${in_lz}" em.lz "${in_lz}" > inein.lz || framework_failure
|
||||||
|
"${LZIP}" -t < inein.lz || test_failed $LINENO
|
||||||
|
"${LZIP}" -d < inein.lz > out2 || test_failed $LINENO
|
||||||
|
cmp in2 out2 || test_failed $LINENO
|
||||||
|
"${LZIP}" -tq inein.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -dq inein.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
[ ! -e inein ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -cdq inein.lz > out2
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
cmp in2 out2 || test_failed $LINENO
|
||||||
|
rm -f out2 inein.lz em.lz || framework_failure
|
||||||
|
|
||||||
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP'
|
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP'
|
||||||
body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000'
|
body='\001\014\000\000\101\376\367\377\377\340\000\200\000\215\357\002\322\001\000\000\000\000\000\000\000\045\000\000\000\000\000\000\000'
|
||||||
cat "${in_lz}" > int.lz || framework_failure
|
cp "${in_lz}" int.lz || framework_failure
|
||||||
printf "LZIP${body}" >> int.lz || framework_failure
|
printf "LZIP${body}" >> int.lz || framework_failure
|
||||||
if "${LZIP}" -tq int.lz ; then
|
if "${LZIP}" -t int.lz ; then
|
||||||
for header in ${headers} ; do
|
for header in ${headers} ; do
|
||||||
printf "${header}${body}" > int.lz || framework_failure
|
printf "${header}${body}" > int.lz || framework_failure
|
||||||
"${LZIP}" -tq int.lz # first member
|
"${LZIP}" -tq int.lz # first member
|
||||||
|
@ -359,7 +399,7 @@ if "${LZIP}" -tq int.lz ; then
|
||||||
[ $? = 2 ] || test_failed $LINENO ${header}
|
[ $? = 2 ] || test_failed $LINENO ${header}
|
||||||
"${LZIP}" -cdq --loose-trailing int.lz > /dev/null
|
"${LZIP}" -cdq --loose-trailing int.lz > /dev/null
|
||||||
[ $? = 2 ] || test_failed $LINENO ${header}
|
[ $? = 2 ] || test_failed $LINENO ${header}
|
||||||
cat "${in_lz}" > int.lz || framework_failure
|
cp "${in_lz}" int.lz || framework_failure
|
||||||
printf "${header}${body}" >> int.lz || framework_failure
|
printf "${header}${body}" >> int.lz || framework_failure
|
||||||
"${LZIP}" -tq int.lz # trailing data
|
"${LZIP}" -tq int.lz # trailing data
|
||||||
[ $? = 2 ] || test_failed $LINENO ${header}
|
[ $? = 2 ] || test_failed $LINENO ${header}
|
||||||
|
@ -381,10 +421,13 @@ if "${LZIP}" -tq int.lz ; then
|
||||||
[ $? = 2 ] || test_failed $LINENO ${header}
|
[ $? = 2 ] || test_failed $LINENO ${header}
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "\nwarning: skipping header test: 'printf' does not work on your system."
|
printf "warning: skipping header test: 'printf' does not work on your system."
|
||||||
fi
|
fi
|
||||||
rm -f int.lz || framework_failure
|
rm -f int.lz || framework_failure
|
||||||
|
|
||||||
|
"${LZIP}" -tq "${fnz_lz}"
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
|
||||||
for i in fox_v2.lz fox_s11.lz fox_de20.lz \
|
for i in fox_v2.lz fox_s11.lz fox_de20.lz \
|
||||||
fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
|
fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
|
||||||
"${LZIP}" -tq "${testdir}"/$i
|
"${LZIP}" -tq "${testdir}"/$i
|
||||||
|
@ -396,13 +439,13 @@ for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
|
||||||
[ $? = 2 ] || test_failed $LINENO $i
|
[ $? = 2 ] || test_failed $LINENO $i
|
||||||
cmp fox out || test_failed $LINENO $i
|
cmp fox out || test_failed $LINENO $i
|
||||||
done
|
done
|
||||||
rm -f fox out || framework_failure
|
rm -f fox || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
|
cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
|
||||||
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
|
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
|
||||||
if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
|
if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
|
||||||
[ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then
|
[ -e trunc.lz ] && cmp in2.lz trunc.lz ; then
|
||||||
for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do
|
for i in 6 20 14664 14683 14684 14685 14686 14687 14688 ; do
|
||||||
dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
|
dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
|
||||||
"${LZIP}" -tq trunc.lz
|
"${LZIP}" -tq trunc.lz
|
||||||
[ $? = 2 ] || test_failed $LINENO $i
|
[ $? = 2 ] || test_failed $LINENO $i
|
||||||
|
@ -414,30 +457,34 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
|
||||||
[ $? = 2 ] || test_failed $LINENO $i
|
[ $? = 2 ] || test_failed $LINENO $i
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
|
printf "warning: skipping truncation test: 'dd' does not work on your system."
|
||||||
fi
|
fi
|
||||||
rm -f in2.lz in3.lz trunc.lz || framework_failure
|
rm -f in2.lz in3.lz trunc.lz || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" > ingin.lz || framework_failure
|
cp "${in_lz}" ingin.lz || framework_failure
|
||||||
printf "g" >> ingin.lz || framework_failure
|
printf "g" >> ingin.lz || framework_failure
|
||||||
cat "${in_lz}" >> ingin.lz || framework_failure
|
cat "${in_lz}" >> ingin.lz || framework_failure
|
||||||
"${LZIP}" -atq ingin.lz
|
"${LZIP}" -atq ingin.lz
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -atq < ingin.lz
|
"${LZIP}" -atq < ingin.lz
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -acdq ingin.lz > /dev/null
|
"${LZIP}" -acdq ingin.lz > out
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -adq < ingin.lz > /dev/null
|
cmp in out || test_failed $LINENO
|
||||||
|
"${LZIP}" -adq < ingin.lz > out
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
cmp in out || test_failed $LINENO
|
||||||
"${LZIP}" -t ingin.lz || test_failed $LINENO
|
"${LZIP}" -t ingin.lz || test_failed $LINENO
|
||||||
"${LZIP}" -t < ingin.lz || test_failed $LINENO
|
"${LZIP}" -t < ingin.lz || test_failed $LINENO
|
||||||
|
"${LZIP}" -dk ingin.lz || test_failed $LINENO
|
||||||
|
cmp in ingin || test_failed $LINENO
|
||||||
"${LZIP}" -cd ingin.lz > out || test_failed $LINENO
|
"${LZIP}" -cd ingin.lz > out || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
"${LZIP}" -d < ingin.lz > out || test_failed $LINENO
|
"${LZIP}" -d < ingin.lz > out || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -d ingin.lz | cmp in - || test_failed $LINENO
|
"${FFEXAMPLE}" -d ingin.lz | cmp in - || test_failed $LINENO
|
||||||
"${FFEXAMPLE}" -r ingin.lz | cmp in2 - || test_failed $LINENO
|
"${FFEXAMPLE}" -r ingin.lz | cmp in2 - || test_failed $LINENO
|
||||||
rm -f in2 out ingin.lz || framework_failure
|
rm -f in2 out ingin ingin.lz || framework_failure
|
||||||
|
|
||||||
echo
|
echo
|
||||||
if [ ${fail} = 0 ] ; then
|
if [ ${fail} = 0 ] ; then
|
||||||
|
|
BIN
testsuite/fox_nz.lz
Normal file
BIN
testsuite/fox_nz.lz
Normal file
Binary file not shown.
|
@ -1,8 +1,7 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
@ -339,8 +338,7 @@ Public License instead of this License.
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue