aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2007-12-09 00:42:33 +0200
committerLasse Collin <lasse.collin@tukaani.org>2007-12-09 00:42:33 +0200
commit5d018dc03549c1ee4958364712fb0c94e1bf2741 (patch)
tree1b211911fb33fddb3f04b77f99e81df23623ffc4 /src/liblzma/api
downloadxz-5d018dc03549c1ee4958364712fb0c94e1bf2741.tar.xz
Imported to git.
Diffstat (limited to 'src/liblzma/api')
-rw-r--r--src/liblzma/api/Makefile.am39
-rw-r--r--src/liblzma/api/lzma.h122
-rw-r--r--src/liblzma/api/lzma/alignment.h60
-rw-r--r--src/liblzma/api/lzma/alone.h82
-rw-r--r--src/liblzma/api/lzma/auto.h41
-rw-r--r--src/liblzma/api/lzma/base.h410
-rw-r--r--src/liblzma/api/lzma/block.h409
-rw-r--r--src/liblzma/api/lzma/check.h128
-rw-r--r--src/liblzma/api/lzma/copy.h29
-rw-r--r--src/liblzma/api/lzma/delta.h49
-rw-r--r--src/liblzma/api/lzma/extra.h114
-rw-r--r--src/liblzma/api/lzma/filter.h166
-rw-r--r--src/liblzma/api/lzma/index.h84
-rw-r--r--src/liblzma/api/lzma/info.h315
-rw-r--r--src/liblzma/api/lzma/init.h85
-rw-r--r--src/liblzma/api/lzma/lzma.h312
-rw-r--r--src/liblzma/api/lzma/memlimit.h157
-rw-r--r--src/liblzma/api/lzma/metadata.h100
-rw-r--r--src/liblzma/api/lzma/raw.h72
-rw-r--r--src/liblzma/api/lzma/simple.h85
-rw-r--r--src/liblzma/api/lzma/stream.h178
-rw-r--r--src/liblzma/api/lzma/stream_flags.h142
-rw-r--r--src/liblzma/api/lzma/subblock.h197
-rw-r--r--src/liblzma/api/lzma/version.h59
-rw-r--r--src/liblzma/api/lzma/vli.h244
25 files changed, 3679 insertions, 0 deletions
diff --git a/src/liblzma/api/Makefile.am b/src/liblzma/api/Makefile.am
new file mode 100644
index 00000000..7f5e6de4
--- /dev/null
+++ b/src/liblzma/api/Makefile.am
@@ -0,0 +1,39 @@
+##
+## Copyright (C) 2007 Lasse Collin
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+
+nobase_include_HEADERS = \
+ lzma.h \
+ lzma/alignment.h \
+ lzma/alone.h \
+ lzma/auto.h \
+ lzma/base.h \
+ lzma/block.h \
+ lzma/check.h \
+ lzma/copy.h \
+ lzma/delta.h \
+ lzma/extra.h \
+ lzma/filter.h \
+ lzma/index.h \
+ lzma/info.h \
+ lzma/init.h \
+ lzma/lzma.h \
+ lzma/memlimit.h \
+ lzma/metadata.h \
+ lzma/raw.h \
+ lzma/simple.h \
+ lzma/stream.h \
+ lzma/stream_flags.h \
+ lzma/subblock.h \
+ lzma/version.h \
+ lzma/vli.h
diff --git a/src/liblzma/api/lzma.h b/src/liblzma/api/lzma.h
new file mode 100644
index 00000000..186ae12c
--- /dev/null
+++ b/src/liblzma/api/lzma.h
@@ -0,0 +1,122 @@
+/**
+ * \file lzma.h
+ * \brief The public API of liblzma
+ *
+ * liblzma is a LZMA compression library with a zlib-like API.
+ * liblzma is based on LZMA SDK found from http://7-zip.org/sdk.html.
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H
+#define LZMA_H
+
+/********************
+ * External headers *
+ ********************/
+
+/* size_t */
+#include <sys/types.h>
+
+/* NULL */
+#include <stddef.h>
+
+/* uint8_t, uint32_t, uint64_t, UINT32_C, UINT64_C, UINT64_MAX. */
+#include <inttypes.h>
+
+
+/******************
+ * GCC extensions *
+ ******************/
+
+/*
+ * GCC extensions are used conditionally in the public API. It doesn't
+ * break anything if these are sometimes enabled and sometimes not, only
+ * affects warnings and optimizations.
+ */
+#if defined(__GNUC__) && __GNUC__ >= 3
+# ifndef lzma_attribute
+# define lzma_attribute(attr) __attribute__(attr)
+# endif
+# ifndef lzma_restrict
+# define lzma_restrict __restrict__
+# endif
+#else
+# ifndef lzma_attribute
+# define lzma_attribute(attr)
+# endif
+# ifndef lzma_restrict
+# define lzma_restrict
+# endif
+#endif
+
+
+/**************
+ * Subheaders *
+ **************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Subheaders check that this is defined. It is to prevent including
+ * them directly from applications.
+ */
+#define LZMA_H_INTERNAL 1
+
+/* Basic features */
+#include "lzma/init.h"
+#include "lzma/base.h"
+#include "lzma/vli.h"
+#include "lzma/filter.h"
+#include "lzma/check.h"
+
+/* Filters */
+#include "lzma/copy.h"
+#include "lzma/subblock.h"
+#include "lzma/simple.h"
+#include "lzma/delta.h"
+#include "lzma/lzma.h"
+
+/* Container formats and Metadata */
+#include "lzma/block.h"
+#include "lzma/index.h"
+#include "lzma/extra.h"
+#include "lzma/metadata.h"
+#include "lzma/stream.h"
+#include "lzma/alone.h"
+#include "lzma/raw.h"
+#include "lzma/auto.h"
+
+/* Advanced features */
+#include "lzma/info.h"
+#include "lzma/alignment.h"
+#include "lzma/stream_flags.h"
+#include "lzma/memlimit.h"
+
+/* Version number */
+#include "lzma/version.h"
+
+/*
+ * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
+ * re-including the subheaders.
+ */
+#undef LZMA_H_INTERNAL
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ifndef LZMA_H */
diff --git a/src/liblzma/api/lzma/alignment.h b/src/liblzma/api/lzma/alignment.h
new file mode 100644
index 00000000..6672656c
--- /dev/null
+++ b/src/liblzma/api/lzma/alignment.h
@@ -0,0 +1,60 @@
+/**
+ * \file lzma/alignment.h
+ * \brief Calculating input and output alignment of filter chains
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Calculates the preferred alignment of the input data
+ *
+ * FIXME desc
+ */
+extern uint32_t lzma_alignment_input(
+ const lzma_options_filter *filters, uint32_t guess);
+
+
+/**
+ * \brief Calculates the alignment of the encoded output
+ *
+ * Knowing the alignment of the output data is useful e.g. in the Block
+ * encoder which tries to align the Compressed Data field optimally.
+ *
+ * \param filters Pointer to lzma_options_filter array, whose last
+ * member must have .id = LZMA_VLI_VALUE_UNKNOWN.
+ * \param guess The value to return if the alignment of the output
+ * is the same as the alignment of the input data.
+ * If you want to always detect this special case,
+ * this guess to zero; this function never returns
+ * zero unless guess is zero.
+ *
+ * \return In most cases, a small positive integer is returned;
+ * for optimal use, the encoded output of this filter
+ * chain should start at on offset that is a multiple of
+ * the returned integer value.
+ *
+ * If the alignment of the output is the same as the input
+ * data (which this function cannot know), \a guess is
+ * returned.
+ *
+ * If an error occurs (that is, unknown Filter IDs or filter
+ * options), UINT32_MAX is returned.
+ */
+extern uint32_t lzma_alignment_output(
+ const lzma_options_filter *filters, uint32_t guess);
diff --git a/src/liblzma/api/lzma/alone.h b/src/liblzma/api/lzma/alone.h
new file mode 100644
index 00000000..1a6b8e27
--- /dev/null
+++ b/src/liblzma/api/lzma/alone.h
@@ -0,0 +1,82 @@
+/**
+ * \file lzma/alone.h
+ * \brief Handling of the legacy LZMA_Alone format
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Options for files in the LZMA_Alone format
+ */
+typedef struct {
+ /**
+ * \brief Uncompressed Size and usage of End of Payload Marker
+ *
+ * In contrast to .lzma Blocks, LZMA_Alone format cannot have both
+ * uncompressed size field in the header and end of payload marker.
+ * If you don't know the uncompressed size beforehand, set it to
+ * LZMA_VLI_VALUE_UNKNOWN and liblzma will embed end of payload
+ * marker.
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief LZMA options
+ *
+ * The LZMA_Alone format supports only one filter: the LZMA filter.
+ *
+ * \note There exists also an undocumented variant of the
+ * LZMA_Alone format, which uses the x86 filter in
+ * addition to LZMA. This format was never supported
+ * by LZMA Utils and is not supported by liblzma either.
+ */
+ lzma_options_lzma lzma;
+
+} lzma_options_alone;
+
+
+/**
+ * \brief Initializes LZMA_Alone encoder
+ *
+ * LZMA_Alone files have the suffix .lzma like the .lzma Stream files.
+ * LZMA_Alone format supports only one filter, the LZMA filter. There is
+ * no support for integrity checks like CRC32.
+ *
+ * Use this format if and only if you need to create files readable by
+ * legacy LZMA tools.
+ *
+ * LZMA_Alone encoder doesn't support LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_alone_encoder(
+ lzma_stream *strm, const lzma_options_alone *options);
+
+
+/**
+ * \brief Initializes decoder for LZMA_Alone file
+ *
+ * The LZMA_Alone decoder supports LZMA_SYNC_FLUSH.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ */
+extern lzma_ret lzma_alone_decoder(lzma_stream *strm);
diff --git a/src/liblzma/api/lzma/auto.h b/src/liblzma/api/lzma/auto.h
new file mode 100644
index 00000000..327e726f
--- /dev/null
+++ b/src/liblzma/api/lzma/auto.h
@@ -0,0 +1,41 @@
+/**
+ * \file lzma/auto.h
+ * \brief Decoder with automatic file format detection
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Decode .lzma Streams and LZMA_Alone files with autodetection
+ *
+ * Autodetects between the .lzma Stream and LZMA_Alone formats, and
+ * calls lzma_stream_decoder_init() or lzma_alone_decoder_init() once
+ * the type of the file has been detected.
+ *
+ * \param strm Pointer to propertily prepared lzma_stream
+ * \param header Pointer to hold a pointer to Extra Records read
+ * from the Header Metadata Block. Use NULL if
+ * you don't care about Extra Records.
+ * \param footer Same as header, but for Footer Metadata Block.
+ *
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR: Cannot allocate memory.
+ */
+extern lzma_ret lzma_auto_decoder(lzma_stream *strm,
+ lzma_extra **header, lzma_extra **footer);
diff --git a/src/liblzma/api/lzma/base.h b/src/liblzma/api/lzma/base.h
new file mode 100644
index 00000000..53cf89f5
--- /dev/null
+++ b/src/liblzma/api/lzma/base.h
@@ -0,0 +1,410 @@
+/**
+ * \file lzma/base.h
+ * \brief Data types and functions used in many places of the public API
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Boolean
+ *
+ * This is here because C89 doesn't have stdbool.h. To set a value for
+ * variables having type lzma_bool, you can use
+ * - C99's `true' and `false' from stdbool.h;
+ * - C++'s internal `true' and `false'; or
+ * - integers one (true) and zero (false).
+ */
+typedef unsigned char lzma_bool;
+
+
+/**
+ * \brief Return values used by several functions in liblzma
+ *
+ * Check the descriptions of specific functions to find out which return
+ * values they can return and the exact meanings of the values in every
+ * situation. The descriptions given here are only suggestive.
+ */
+typedef enum {
+ LZMA_OK = 0,
+ /**<
+ * \brief Operation completed successfully
+ */
+
+ LZMA_STREAM_END = 1,
+ /**<
+ * \brief End of stream was reached
+ *
+ * The application should pick the last remaining output
+ * bytes from strm->next_out.
+ */
+
+ LZMA_PROG_ERROR = -2,
+ /**<
+ * \brief Programming error
+ *
+ * This indicates that the arguments given to the function are
+ * invalid or the internal state of the decoder is corrupt.
+ * - Function arguments are invalid or the structures
+ * pointed by the argument pointers are invalid
+ * e.g. if strm->next_out has been set to NULL and
+ * strm->avail_out > 0 when calling lzma_code().
+ * - lzma_* functions have been called in wrong order
+ * e.g. lzma_code() was called right after lzma_end().
+ * - If errors occur randomly, the reason might be flaky
+ * hardware.
+ *
+ * If you think that your code is correct, this error code
+ * can be a sign of a bug in liblzma. See the documentation
+ * how to report bugs.
+ */
+
+ LZMA_DATA_ERROR = -3,
+ /**<
+ * \brief Data is corrupt
+ *
+ * - Encoder: The input size doesn't match the uncompressed
+ * size given to lzma_*_encoder_init().
+ * - Decoder: The input is corrupt. This includes corrupted
+ * header, corrupted compressed data, and unmatching
+ * integrity Check.
+ *
+ * \todo What can be done if encoder returns this?
+ * Probably can continue by fixing the input
+ * amount, but make sure.
+ */
+
+ LZMA_MEM_ERROR = -4,
+ /**<
+ * \brief Cannot allocate memory
+ *
+ * Memory allocation failed.
+ */
+
+ LZMA_BUF_ERROR = -5,
+ /**<
+ * \brief No progress is possible
+ *
+ * This may happen when avail_in or avail_out is zero.
+ *
+ * \note This error is not fatal. Coding can continue
+ * normally once the reason for this error has
+ * been fixed.
+ */
+
+ LZMA_HEADER_ERROR = -6,
+ /**<
+ * \brief Invalid or unsupported header
+ *
+ * Invalid or unsupported options, for example
+ * - unsupported filter(s) or filter options; or
+ * - reserved bits set in headers (decoder only).
+ *
+ * Rebuilding liblzma with more features enabled, or
+ * upgrading to a newer version of liblzma may help.
+ */
+
+ LZMA_UNSUPPORTED_CHECK = -7,
+ /**<
+ * \brief Check type is unknown
+ *
+ * The type of Check is not supported, and thus the Check
+ * cannot be calculated. In the encoder, this is an error.
+ * In the decoder, this is only a warning and decoding can
+ * still proceed normally (but the Check is ignored).
+ */
+} lzma_ret;
+
+
+/**
+ * \brief The `action' argument for lzma_code()
+ */
+typedef enum {
+ LZMA_RUN = 0,
+ /**<
+ * Encoder: Encode as much input as possible. Some internal
+ * buffering will probably be done (depends on the filter
+ * chain in use), which causes latency: the input used won't
+ * usually be decodeable from the output of the same
+ * lzma_code() call.
+ *
+ * Decoder: Decode as much input as possible and produce as
+ * much output as possible. This action provides best
+ * throughput, but may introduce latency, because the
+ * decoder may decode more data into its internal buffers
+ * than that fits into next_out.
+ */
+
+ LZMA_SYNC_FLUSH = 1,
+ /**<
+ * Encoder: Makes all the data given to liblzma via next_in
+ * available in next_out without resetting the filters. Call
+ * lzma_code() with LZMA_SYNC_FLUSH until it returns
+ * LZMA_STREAM_END. Then continue encoding normally.
+ *
+ * \note Synchronous flushing is supported only by
+ * some filters. Some filters support it only
+ * partially.
+ *
+ * Decoder: Asks the decoder to decode only as much as is
+ * needed to fill next_out. This decreases latency with some
+ * filters, but is likely to decrease also throughput. It is
+ * a good idea to use this flag only when it is likely that
+ * you don't need more output soon.
+ *
+ * \note With decoder, this is not comparable to
+ * zlib's Z_SYNC_FLUSH.
+ */
+
+ LZMA_FULL_FLUSH = 2,
+ /**<
+ * Finishes encoding of the current Data Block. All the input
+ * data going to the current Data Block must have been given
+ * to the encoder (the last bytes can still be pending in
+ * next_in). Call lzma_code() with LZMA_FULL_FLUSH until
+ * it returns LZMA_STREAM_END. Then continue normally with
+ * LZMA_RUN or finish the Stream with LZMA_FINISH.
+ *
+ * This action is supported only by Multi-Block Stream
+ * encoder. If there is no unfinished Data Block, no empty
+ * Data Block is created.
+ */
+
+ LZMA_FINISH = 3
+ /**<
+ * Finishes the encoding operation. All the input data must
+ * have been given to the encoder (the last bytes can still
+ * be pending in next_in). Call lzma_code() with LZMA_FINISH
+ * until it returns LZMA_STREAM_END.
+ *
+ * This action is not supported by decoders.
+ */
+} lzma_action;
+
+
+/**
+ * \brief Custom functions for memory handling
+ *
+ * A pointer to lzma_allocator may be passed via lzma_stream structure
+ * to liblzma. The library will use these functions for memory handling
+ * instead of the default malloc() and free().
+ *
+ * liblzma doesn't make an internal copy of lzma_allocator. Thus, it is
+ * OK to change these function pointers in the middle of the coding
+ * process, but obviously it must be done carefully to make sure that the
+ * replacement `free' can deallocate memory allocated by the earlier
+ * `alloc' function(s).
+ */
+typedef struct {
+ /**
+ * \brief Pointer to custom memory allocation function
+ *
+ * Set this to point to your custom memory allocation function.
+ * It can be useful for example if you want to limit how much
+ * memory liblzma is allowed to use: for this, you may use
+ * a pointer to lzma_memory_alloc().
+ *
+ * If you don't want a custom allocator, but still want
+ * custom free(), set this to NULL and liblzma will use
+ * the standard malloc().
+ *
+ * \param opaque lzma_allocator.opaque (see below)
+ * \param nmemb Number of elements like in calloc().
+ * liblzma will always set nmemb to 1.
+ * This argument exists only for
+ * compatibility with zlib and libbzip2.
+ * \param size Size of an element in bytes.
+ * liblzma never sets this to zero.
+ *
+ * \return Pointer to the beginning of a memory block of
+ * size nmemb * size, or NULL if allocation fails
+ * for some reason. When allocation fails, functions
+ * of liblzma return LZMA_MEM_ERROR.
+ */
+ void *(*alloc)(void *opaque, size_t nmemb, size_t size);
+
+ /**
+ * \brief Pointer to custom memory freeing function
+ *
+ * Set this to point to your custom memory freeing function.
+ * If lzma_memory_alloc() is used as allocator, this should
+ * be set to lzma_memory_free().
+ *
+ * If you don't want a custom freeing function, but still
+ * want a custom allocator, set this to NULL and liblzma
+ * will use the standard free().
+ *
+ * \param opaque lzma_allocator.opaque (see below)
+ * \param ptr Pointer returned by
+ * lzma_allocator.alloc(), or when it
+ * is set to NULL, a pointer returned
+ * by the standard malloc().
+ */
+ void (*free)(void *opaque, void *ptr);
+
+ /**
+ * \brief Pointer passed to .alloc() and .free()
+ *
+ * opaque is passed as the first argument to lzma_allocator.alloc()
+ * and lzma_allocator.free(). This intended to ease implementing
+ * custom memory allocation functions for use with liblzma.
+ *
+ * When using lzma_memory_alloc() and lzma_memory_free(), opaque
+ * must point to lzma_memory_limitter structure allocated and
+ * initialized with lzma_memory_limitter_create().
+ *
+ * If you don't need this, you should set it to NULL.
+ */
+ void *opaque;
+
+} lzma_allocator;
+
+
+/**
+ * \brief Internal data structure
+ *
+ * The contents of this structure is not visible outside the library.
+ */
+typedef struct lzma_internal_s lzma_internal;
+
+
+/**
+ * \brief Passing data to and from liblzma
+ *
+ * The lzma_stream structure is used for
+ * - passing pointers to input and output buffers to liblzma;
+ * - defining custom memory hander functions; and
+ * - holding a pointer to coder-specific internal data structures.
+ *
+ * Before calling any of the lzma_*_init() functions the first time,
+ * the application must reset lzma_stream to LZMA_STREAM_INIT. The
+ * lzma_*_init() function will verify the options, allocate internal
+ * data structures and store pointer to them into `internal'. Finally
+ * total_in and total_out are reset to zero. In contrast to zlib,
+ * next_in and avail_in are ignored by the initialization functions.
+ *
+ * The actual coding is done with the lzma_code() function. Application
+ * must update next_in, avail_in, next_out, and avail_out between
+ * calls to lzma_decode() just like with zlib.
+ *
+ * In contrast to zlib, even the decoder requires that there always
+ * is at least one byte space in next_out; if avail_out == 0,
+ * LZMA_BUF_ERROR is returned immediatelly. This shouldn't be a problem
+ * for most applications that already use zlib, but it's still worth
+ * checking your application.
+ *
+ * Application may modify values of total_in and total_out as it wants.
+ * They are updated by liblzma to match the amount of data read and
+ * written, but liblzma doesn't use the values internally.
+ *
+ * Application must not touch the `internal' pointer.
+ */
+typedef struct {
+ uint8_t *next_in; /**< Pointer to the next input byte. */
+ size_t avail_in; /**< Number of available input bytes in next_in. */
+ uint64_t total_in; /**< Total number of bytes read by liblzma. */
+
+ uint8_t *next_out; /**< Pointer to the next output position. */
+ size_t avail_out; /**< Amount of free space in next_out. */
+ uint64_t total_out; /**< Total number of bytes written by liblzma. */
+
+ /**
+ * Custom memory allocation functions. Set to NULL to use
+ * the standard malloc() and free().
+ */
+ lzma_allocator *allocator;
+
+ /** Internal state is not visible to outsiders. */
+ lzma_internal *internal;
+
+} lzma_stream;
+
+
+/**
+ * \brief Initialization for lzma_stream
+ *
+ * When you declare an instance of lzma_stream, you can immediatelly
+ * initialize it so that initialization functions know that no memory
+ * has been allocated yet:
+ *
+ * lzma_stream strm = LZMA_STREAM_INIT;
+ */
+#define LZMA_STREAM_INIT { NULL, 0, 0, NULL, 0, 0, NULL, NULL }
+
+
+/**
+ * \brief Initialization for lzma_stream
+ *
+ * This is like LZMA_STREAM_INIT, but this can be used when the lzma_stream
+ * has already been allocated:
+ *
+ * lzma_stream *strm = malloc(sizeof(lzma_stream));
+ * if (strm == NULL)
+ * return LZMA_MEM_ERROR;
+ * *strm = LZMA_STREAM_INIT_VAR;
+ */
+extern const lzma_stream LZMA_STREAM_INIT_VAR;
+
+
+/**
+ * \brief Encodes or decodes data
+ *
+ * Once the lzma_stream has been successfully initialized (e.g. with
+ * lzma_stream_encoder_single()), the actual encoding or decoding is
+ * done using this function.
+ *
+ * \return Some coders may have more exact meaning for different return
+ * values, which are mentioned separately in the description of
+ * the initialization functions. Here are the typical meanings:
+ * - LZMA_OK: So far all good.
+ * - LZMA_STREAM_END:
+ * - Encoder: LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
+ * LZMA_FINISH completed.
+ * - Decoder: End of uncompressed data was reached.
+ * - LZMA_BUF_ERROR: Unable to progress. Provide more input or
+ * output space, and call this function again. This cannot
+ * occur if both avail_in and avail_out were non-zero (or
+ * there's a bug in liblzma).
+ * - LZMA_MEM_ERROR: Unable to allocate memory. Due to lazy
+ * programming, the coding cannot continue even if the
+ * application could free more memory. The next call must
+ * be lzma_end() or some initialization function.
+ * - LZMA_DATA_ERROR:
+ * - Encoder: Filter(s) cannot process the given data.
+ * - Decoder: Compressed data is corrupt.
+ * - LZMA_HEADER_ERROR: Unsupported options. Rebuilding liblzma
+ * with more features enabled or upgrading to a newer version
+ * may help, although usually this is a sign of invalid options
+ * (encoder) or corrupted input data (decoder).
+ * - LZMA_PROG_ERROR: Invalid arguments or the internal state
+ * of the coder is corrupt.
+ */
+extern lzma_ret lzma_code(lzma_stream *strm, lzma_action action);
+
+
+/**
+ * \brief Frees memory allocated for the coder data structures
+ *
+ * \param strm Pointer to lzma_stream that is at least initialized
+ * with LZMA_STREAM_INIT.
+ *
+ * \note zlib indicates an error if application end()s unfinished
+ * stream. liblzma doesn't do this, and assumes that
+ * application knows what it is doing.
+ */
+extern void lzma_end(lzma_stream *strm);
diff --git a/src/liblzma/api/lzma/block.h b/src/liblzma/api/lzma/block.h
new file mode 100644
index 00000000..210c1d87
--- /dev/null
+++ b/src/liblzma/api/lzma/block.h
@@ -0,0 +1,409 @@
+/**
+ * \file lzma/block.h
+ * \brief .lzma Block handling
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Options for the Block Header encoder and decoder
+ *
+ * Different things use different parts of this structure. Some read
+ * some members, other functions write, and some do both. Only the
+ * members listed for reading need to be initialized when the specified
+ * functions are called. The members marked for writing will be assigned
+ * new values at some point either by calling the given function or by
+ * later calls to lzma_code().
+ */
+typedef struct {
+ /**
+ * \brief Type of integrity Check
+ *
+ * The type of the integrity Check is not stored into the Block
+ * Header, thus its value must be provided also when decoding.
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_check_type check;
+
+ /**
+ * \brief Precense of CRC32 of the Block Header
+ *
+ * Set this to true if CRC32 of the Block Header should be
+ * calculated and stored in the Block Header.
+ *
+ * There is no way to autodetect if CRC32 is present in the Block
+ * Header, thus this information must be provided also when decoding.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ * - lzma_block_header_decoder()
+ */
+ lzma_bool has_crc32;
+
+ /**
+ * \brief Usage of End of Payload Marker
+ *
+ * If this is true, End of Payload Marker is used even if
+ * Uncompressed Size is known.
+ *
+ * Read by:
+ * - lzma_block_header_encoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ */
+ lzma_bool has_eopm;
+
+ /**
+ * \brief True if the Block is a Metadata Block
+ *
+ * If this is true, the Metadata bit will be set in the Block Header.
+ * It is up to the application to store correctly formatted data
+ * into Metadata Block.
+ *
+ * Read by:
+ * - lzma_block_header_encoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ */
+ lzma_bool is_metadata;
+
+ /**
+ * \brief True if Uncompressed Size is in Block Footer
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_bool has_uncompressed_size_in_footer;
+
+ /**
+ * \brief True if Backward Size is in Block Footer
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_bool has_backward_size;
+
+ /**
+ * \brief True if Block coder should take care of Padding
+ *
+ * In liblzma, Stream decoder sets this to true when decoding
+ * Header Metadata Block or Data Blocks from Multi-Block Stream,
+ * and to false when decoding Single-Block Stream or Footer
+ * Metadata Block from a Multi-Block Stream.
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_bool handle_padding;
+
+ /**
+ * \brief Size of the Compressed Data in bytes
+ *
+ * Usually you don't know this value when encoding in streamed mode.
+ * In non-streamed mode you can reserve space for this field when
+ * encoding the Block Header the first time, and then re-encode the
+ * Block Header and copy it over the original one after the encoding
+ * of the Block has been finished.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_vli compressed_size;
+
+ /**
+ * \brief Uncompressed Size in bytes
+ *
+ * Encoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is stored
+ * to the Uncompressed Size field in the Block Header. The real
+ * uncompressed size of the data being compressed must match
+ * the Uncompressed Size or LZMA_HEADER_ERROR is returned.
+ *
+ * If Uncompressed Size is unknown, End of Payload Marker must
+ * be used. If uncompressed_size == LZMA_VLI_VALUE_UNKNOWN and
+ * has_eopm == 0, LZMA_HEADER_ERROR will be returned.
+ *
+ * Decoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is
+ * compared to the real Uncompressed Size. If they do not match,
+ * LZMA_HEADER_ERROR is returned.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Number of bytes to reserve for Compressed Size
+ *
+ * This is useful if you want to be able to store the Compressed Size
+ * to the Block Header, but you don't know it when starting to encode.
+ * Setting this to non-zero value at maximum of LZMA_VLI_BYTES_MAX,
+ * the Block Header encoder will force the Compressed Size field to
+ * occupy specified number of bytes. You can later rewrite the Block
+ * Header to contain correct information by using otherwise identical
+ * lzma_options_block structure except the correct compressed_size.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ */
+ uint32_t compressed_reserve;
+
+ /**
+ * \brief Number of bytes to reserve for Uncompressed Size
+ *
+ * See the description of compressed_size above.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder()
+ */
+ uint32_t uncompressed_reserve;
+
+ /**
+ * \brief Total Size of the Block in bytes
+ *
+ * This is useful in the decoder, which can verify the Total Size
+ * if it is known from Index.
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_vli total_size;
+
+ /**
+ * \brief Upper limit of Total Size
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_vli total_limit;
+
+ /**
+ * \brief Upper limit of Uncompressed Size
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ */
+ lzma_vli uncompressed_limit;
+
+ /**
+ * \brief Array of filters
+ *
+ * There can be at maximum of seven filters. The end of the array
+ * is marked with .id = LZMA_VLI_VALUE_UNKNOWN. Minimum number of
+ * filters is zero; in that case, an implicit Copy filter is used.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_header_decoder(): Note that this does NOT free()
+ * the old filter options structures. If decoding fails, the
+ * caller must take care of freeing the options structures
+ * that may have been allocated and decoded before the error
+ * occurred.
+ */
+ lzma_options_filter filters[8];
+
+ /**
+ * \brief Size of the Padding field
+ *
+ * The Padding field exist to allow aligning the Compressed Data field
+ * optimally in the Block. See lzma_options_stream.alignment in
+ * stream.h for more information.
+ *
+ * If you want the Block Header encoder to automatically calculate
+ * optimal size for the Padding field by looking at the information
+ * in filters[], set this to LZMA_BLOCK_HEADER_PADDING_AUTO. In that
+ * case, you must also set the aligmnet variable to tell the the
+ * encoder the aligmnet of the beginning of the Block Header.
+ *
+ * The decoder never sets this to LZMA_BLOCK_HEADER_PADDING_AUTO.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder(): Note that this doesn't
+ * accept LZMA_BLOCK_HEADER_PADDING_AUTO.
+ *
+ * Written by (these never set padding to
+ * LZMA_BLOCK_HEADER_PADDING_AUTO):
+ * - lzma_block_header_size()
+ * - lzma_block_header_decoder()
+ */
+ int32_t padding;
+# define LZMA_BLOCK_HEADER_PADDING_AUTO (-1)
+# define LZMA_BLOCK_HEADER_PADDING_MIN 0
+# define LZMA_BLOCK_HEADER_PADDING_MAX 31
+
+ /**
+ * \brief Alignment of the beginning of the Block Header
+ *
+ * This variable is read only if padding has been set to
+ * LZMA_BLOCK_HEADER_PADDING_AUTO.
+ *
+ * Read by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_encoder()
+ */
+ uint32_t alignment;
+
+ /**
+ * \brief Size of the Block Header
+ *
+ * Read by:
+ * - lzma_block_encoder()
+ * - lzma_block_decoder()
+ *
+ * Written by:
+ * - lzma_block_header_size()
+ * - lzma_block_header_decoder()
+ */
+ uint32_t header_size;
+
+} lzma_options_block;
+
+
+/**
+ * \brief Calculates the size of Header Padding and Block Header
+ *
+ * \return - LZMA_OK: Size calculated successfully and stored to
+ * options->header_size.
+ * - LZMA_HEADER_ERROR: Unsupported filters or filter options.
+ * - LZMA_PROG_ERROR: Invalid options
+ *
+ * \note This doesn't check that all the options are valid i.e. this
+ * may return LZMA_OK even if lzma_block_header_encode() or
+ * lzma_block_encoder() would fail.
+ */
+extern lzma_ret lzma_block_header_size(lzma_options_block *options);
+
+
+/**
+ * \brief Encodes Block Header
+ *
+ * Encoding of the Block options is done with a single call instead of
+ * first initializing and then doing the actual work with lzma_code().
+ *
+ * \param out Beginning of the output buffer. This must be
+ * at least options->header_size bytes.
+ * \param options Block options to be encoded.
+ *
+ * \return - LZMA_OK: Encoding was successful. options->header_size
+ * bytes were written to output buffer.
+ * - LZMA_HEADER_ERROR: Invalid or unsupported options.
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_block_header_encode(
+ uint8_t *out, const lzma_options_block *options);
+
+
+/**
+ * \brief Initializes Block Header decoder
+ *
+ * Because the results of this decoder are placed into *options,
+ * strm->next_in, strm->avail_in, and strm->total_in are not used.
+ *
+ * The only valid `action' with lzma_code() is LZMA_RUN.
+ *
+ * \return - LZMA_OK: Encoding was successful. options->header_size
+ * bytes were written to output buffer.
+ * - LZMA_HEADER_ERROR: Invalid or unsupported options.
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_block_header_decoder(
+ lzma_stream *strm, lzma_options_block *options);
+
+
+/**
+ * \brief Initializes .lzma Block encoder
+ *
+ * This function is required for multi-thread encoding. It may also be
+ * useful when implementing custom file formats.
+ *
+ * \return - LZMA_OK: All good, continue with lzma_code().
+ * - LZMA_MEM_ERROR
+ * - LZMA_HEADER_ERROR
+ * - LZMA_DATA_ERROR: Limits (total_limit and uncompressed_limit)
+ * have been reached already.
+ * - LZMA_UNSUPPORTED_CHECK: options->check specfies a Check
+ * that is not supported by this buid of liblzma. Initializing
+ * the encoder failed.
+ * - LZMA_PROG_ERROR
+ *
+ * lzma_code() can return FIXME
+ */
+extern lzma_ret lzma_block_encoder(
+ lzma_stream *strm, lzma_options_block *options);
+
+
+/**
+ * \brief Initializes decoder for .lzma Block
+ *
+ * \return - LZMA_OK: All good, continue with lzma_code().
+ * - LZMA_UNSUPPORTED_CHECK: Initialization was successful, but
+ * the given Check type is not supported, thus Check will be
+ * ignored.
+ * - LZMA_PROG_ERROR
+ * - LZMA_MEM_ERROR
+ */
+extern lzma_ret lzma_block_decoder(
+ lzma_stream *strm, lzma_options_block *options);
diff --git a/src/liblzma/api/lzma/check.h b/src/liblzma/api/lzma/check.h
new file mode 100644
index 00000000..4a2a453b
--- /dev/null
+++ b/src/liblzma/api/lzma/check.h
@@ -0,0 +1,128 @@
+/**
+ * \file lzma/check.h
+ * \brief Integrity checks
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Type of the Check
+ *
+ * The .lzma format supports multiple types of Checks that are calculated
+ * from the uncompressed data (unless it is empty; then it's calculated
+ * from Block Header).
+ */
+typedef enum {
+ LZMA_CHECK_NONE = 0,
+ /**<
+ * No Check is calculated.
+ *
+ * Size of the Check field: 0 bytes
+ */
+
+ LZMA_CHECK_CRC32 = 1,
+ /**<
+ * CRC32 using the polynomial from the IEEE 802.3 standard
+ *
+ * Size of the Check field: 4 bytes
+ */
+
+ LZMA_CHECK_CRC64 = 3,
+ /**<
+ * CRC64 using the polynomial from the ECMA-182 standard
+ *
+ * Size of the Check field: 8 bytes
+ */
+
+ LZMA_CHECK_SHA256 = 5
+ /**<
+ * SHA-256
+ *
+ * Size of the Check field: 32 bytes
+ */
+} lzma_check_type;
+
+
+/**
+ * \brief Maximum valid Check ID
+ *
+ * The .lzma file format specification specifies eight Check IDs (0-7). Some
+ * of them are only reserved i.e. no actual Check algorithm has been assigned.
+ * Still liblzma accepts any of these eight IDs for future compatibility
+ * when decoding files. If a valid but unsupported Check ID is detected,
+ * liblzma indicates a warning with LZMA_UNSUPPORTED_CHECK.
+ *
+ * FIXME bad desc
+ */
+#define LZMA_CHECK_ID_MAX 7
+
+
+/**
+ * \brief Check IDs supported by this liblzma build
+ *
+ * If lzma_available_checks[n] is true, the Check ID n is supported by this
+ * liblzma build. You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32
+ * are always available.
+ */
+extern const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1];
+
+
+/**
+ * \brief Size of the Check field with different Check IDs
+ *
+ * Although not all Check IDs have a check algorithm associated, the size of
+ * every Check is already frozen. This array contains the size (in bytes) of
+ * the Check field with specified Check ID. The values are taken from the
+ * section 2.2.2 of the .lzma file format specification:
+ * { 0, 4, 4, 8, 16, 32, 32, 64 }
+ */
+extern const uint32_t lzma_check_sizes[LZMA_CHECK_ID_MAX + 1];
+
+
+/**
+ * \brief Calculate CRC32
+ *
+ * Calculates CRC32 using the polynomial from the IEEE 802.3 standard.
+ *
+ * \param buf Pointer to the input buffer
+ * \param size Size of the input buffer
+ * \param crc Previously returned CRC value. This is used to
+ * calculate the CRC of a big buffer in smaller chunks.
+ * Set to zero when there is no previous value.
+ *
+ * \return Updated CRC value, which can be passed to this function
+ * again to continue CRC calculation.
+ */
+extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
+
+
+/**
+ * \brief Calculate CRC64
+ *
+ * Calculates CRC64 using the polynomial from the ECMA-182 standard.
+ *
+ * This function is used similarly to lzma_crc32(). See its documentation.
+ */
+extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
+
+
+/*
+ * SHA256 functions are currently not exported to public API.
+ * Contact the author if you think it should be.
+ */
diff --git a/src/liblzma/api/lzma/copy.h b/src/liblzma/api/lzma/copy.h
new file mode 100644
index 00000000..f5617462
--- /dev/null
+++ b/src/liblzma/api/lzma/copy.h
@@ -0,0 +1,29 @@
+/**
+ * \file lzma/copy.h
+ * \brief Copy filter
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter ID
+ *
+ * Filter ID of the Copy filter. This is used as lzma_options_filter.id.
+ */
+#define LZMA_FILTER_COPY LZMA_VLI_C(0x00)
diff --git a/src/liblzma/api/lzma/delta.h b/src/liblzma/api/lzma/delta.h
new file mode 100644
index 00000000..58afec18
--- /dev/null
+++ b/src/liblzma/api/lzma/delta.h
@@ -0,0 +1,49 @@
+/**
+ * \file lzma/delta.h
+ * \brief Delta filter
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter ID
+ *
+ * Filter ID of the Delta filter. This is used as lzma_options_filter.id.
+ */
+#define LZMA_FILTER_DELTA LZMA_VLI_C(0x20)
+
+
+/**
+ * \brief Options for the Delta filter
+ *
+ * These options are needed by both encoder and decoder.
+ */
+typedef struct {
+ /**
+ * \brief Delta distance as bytes
+ *
+ * Examples:
+ * - 16-bit stereo audio: distance = 4 bytes
+ * - 24-bit RGB image data: distance = 3 bytes
+ */
+ uint32_t distance;
+# define LZMA_DELTA_DISTANCE_MIN 1
+# define LZMA_DELTA_DISTANCE_MAX 256
+
+} lzma_options_delta;
diff --git a/src/liblzma/api/lzma/extra.h b/src/liblzma/api/lzma/extra.h
new file mode 100644
index 00000000..29426a74
--- /dev/null
+++ b/src/liblzma/api/lzma/extra.h
@@ -0,0 +1,114 @@
+/**
+ * \file lzma/extra.h
+ * \brief Handling of Extra Records in Metadata
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/*
+ * Extra Record IDs
+ *
+ * See the .lzma file format specification for description what each
+ * Extra Record type exactly means.
+ *
+ * If you ever need to update .lzma files with Extra Records, note that
+ * the Record IDs are divided in two categories:
+ * - Safe-to-Copy Records may be preserved as is when the
+ * Stream is modified in ways that don't change the actual
+ * uncompressed data. Examples of such operatings include
+ * recompressing and adding, modifying, or deleting unrelated
+ * Extra Records.
+ * - Unsafe-to-Copy Records should be removed (and possibly
+ * recreated) when any kind of changes are made to the Stream.
+ */
+
+#define LZMA_EXTRA_PADDING 0x00
+#define LZMA_EXTRA_OPENPGP 0x01
+#define LZMA_EXTRA_FILTERS 0x02
+#define LZMA_EXTRA_COMMENT 0x03
+#define LZMA_EXTRA_CHECKS 0x04
+#define LZMA_EXTRA_FILENAME 0x05
+#define LZMA_EXTRA_MTIME 0x07
+#define LZMA_EXTRA_MTIME_HR 0x09
+#define LZMA_EXTRA_MIME_TYPE 0x0B
+#define LZMA_EXTRA_HOMEPAGE 0x0D
+
+
+/**
+ * \brief Extra Records
+ *
+ * The .lzma format provides a way to store custom information along
+ * the actual compressed content. Information about these Records
+ * are passed to and from liblzma via this linked list.
+ */
+typedef struct lzma_extra_s lzma_extra;
+struct lzma_extra_s {
+ /**
+ * \brief Pointer to the next Extra Record
+ *
+ * This is NULL on the last Extra Record.
+ */
+ lzma_extra *next;
+
+ /**
+ * \brief Record ID
+ *
+ * Extra Record IDs are divided in three categories:
+ * - Zero is a special case used for padding. It doesn't have
+ * Size of Data fields.
+ * - Odd IDs (1, 3, 5, ...) are Safe-to-Copy IDs.
+ * These can be preserved as is if the Stream is
+ * modified in a way that doesn't alter the actual
+ * uncompressed content.
+ * - Even IDs (2, 4, 6, ...) are Unsafe-to-Copy IDs.
+ * If the .lzma Stream is modified in any way,
+ * the Extra Records having a sensitive ID should
+ * be removed or updated accordingly.
+ *
+ * Refer to the .lzma file format specification for
+ * the up to date list of Extra Record IDs.
+ */
+ lzma_vli id;
+
+ /**
+ * \brief Size of the Record data
+ *
+ * In case of strings, this should not include the
+ * trailing '\0'.
+ */
+ size_t size;
+
+ /**
+ * \brief Record data
+ *
+ * Record data is often a string in UTF-8 encoding,
+ * but it can be arbitrary binary data. In case of
+ * strings, the trailing '\0' is usually not stored
+ * in the .lzma file.
+ *
+ * To ease working with Extra Records containing strings,
+ * liblzma always adds '\0' to the end of data even when
+ * it wasn't present in the .lzma file. This '\0' is not
+ * counted in the size of the data.
+ */
+ uint8_t *data;
+};
+
+
+extern void lzma_extra_free(lzma_extra *extra, lzma_allocator *allocator);
diff --git a/src/liblzma/api/lzma/filter.h b/src/liblzma/api/lzma/filter.h
new file mode 100644
index 00000000..a8bdd4bd
--- /dev/null
+++ b/src/liblzma/api/lzma/filter.h
@@ -0,0 +1,166 @@
+/**
+ * \file lzma/filter.h
+ * \brief Common filter related types
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter options
+ *
+ * This structure is used to pass Filter ID and a pointer filter's options
+ * to liblzma.
+ */
+typedef struct {
+ /**
+ * \brief Filter ID
+ *
+ * Use constants whose name begin with `LZMA_FILTER_' to specify
+ * different filters. In an array of lzma_option_filter structures,
+ * use LZMA_VLI_VALUE_UNKNOWN to indicate end of filters.
+ */
+ lzma_vli id;
+
+ /**
+ * \brief Pointer to filter-specific options structure
+ *
+ * If the filter doesn't need options, set this to NULL. If id is
+ * set to LZMA_VLI_VALUE_UNKNOWN, options is ignored, and thus
+ * doesn't need be initialized.
+ *
+ * Some filters support changing the options in the middle of
+ * the encoding process. These filters store the pointer of the
+ * options structure and communicate with the application via
+ * modifications of the options structure.
+ */
+ void *options;
+
+} lzma_options_filter;
+
+
+/**
+ * \brief Filters available for encoding
+ *
+ * Pointer to an array containing the list of available Filter IDs that
+ * can be used for encoding. The last element is LZMA_VLI_VALUE_UNKNOWN.
+ *
+ * If lzma_available_filter_encoders[0] == LZMA_VLI_VALUE_UNKNOWN, the
+ * encoder components haven't been built at all. This means that the
+ * encoding-specific functions are probably missing from the library
+ * API/ABI completely.
+ */
+extern const lzma_vli *const lzma_available_filter_encoders;
+
+
+/**
+ * \brief Filters available for decoding
+ *
+ * Pointer to an array containing the list of available Filter IDs that
+ * can be used for decoding. The last element is LZMA_VLI_VALUE_UNKNOWN.
+ *
+ * If lzma_available_filter_decoders[0] == LZMA_VLI_VALUE_UNKNOWN, the
+ * decoder components haven't been built at all. This means that the
+ * decoding-specific functions are probably missing from the library
+ * API/ABI completely.
+ */
+extern const lzma_vli *const lzma_available_filter_decoders;
+
+
+/**
+ * \brief Calculate rough memory requirements for given filter chain
+ *
+ * \param filters Array of filters terminated with
+ * .id == LZMA_VLI_VALUE_UNKNOWN.
+ * \param is_encoder Set to true when calculating memory requirements
+ * of an encoder; false for decoder.
+ *
+ * \return Number of mebibytes (MiB i.e. 2^20) required for the given
+ * encoder or decoder filter chain.
+ *
+ * \note If calculating memory requirements of encoder, lzma_init() or
+ * lzma_init_encoder() must have been called earlier. Similarly,
+ * if calculating memory requirements of decoder, lzma_init() or
+ * lzma_init_decoder() must have been called earlier.
+ */
+extern uint32_t lzma_memory_usage(
+ const lzma_options_filter *filters, lzma_bool is_encoder);
+
+
+/**
+ * \brief Calculates encoded size of a Filter Flags field
+ *
+ * Knowing the size of Filter Flags is useful to know when allocating
+ * memory to hold the encoded Filter Flags.
+ *
+ * \param size Pointer to integer to hold the calculated size
+ * \param options Filter ID and associated options whose encoded
+ * size is to be calculted
+ *
+ * \return - LZMA_OK: *size set successfully. Note that this doesn't
+ * guarantee that options->options is valid, thus
+ * lzma_filter_flags_encode() may still fail.
+ * - LZMA_HEADER_ERROR: Unknown Filter ID or unsupported options.
+ * - LZMA_PROG_ERROR: Invalid options
+ *
+ * \note If you need to calculate size of List of Filter Flags,
+ * you need to loop over every lzma_options_filter entry.
+ */
+extern lzma_ret lzma_filter_flags_size(
+ uint32_t *size, const lzma_options_filter *options);
+
+
+/**
+ * \brief Encodes Filter Flags into given buffer
+ *
+ * In contrast to some functions, this doesn't allocate the needed buffer.
+ * This is due to how this function is used internally by liblzma.
+ *
+ * \param out Beginning of the output buffer
+ * \param out_pos out[*out_pos] is the next write position. This
+ * is updated by the encoder.
+ * \param out_size out[out_size] is the first byte to not write.
+ * \param options Filter options to be encoded
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_HEADER_ERROR: Invalid or unsupported options.
+ * - LZMA_PROG_ERROR: Invalid options or not enough output
+ * buffer space (you should have checked it with
+ * lzma_filter_flags_size()).
+ */
+extern lzma_ret lzma_filter_flags_encode(uint8_t *out, size_t *out_pos,
+ size_t out_size, const lzma_options_filter *options);
+
+
+/**
+ * \brief Initializes Filter Flags decoder
+ *
+ * The decoded result is stored into *options. options->options is
+ * initialized but the old value is NOT free()d.
+ *
+ * Because the results of this decoder are placed into *options,
+ * strm->next_in, strm->avail_in, and strm->total_in are not used
+ * when calling lzma_code(). The only valid action for lzma_code()
+ * is LZMA_RUN
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_filter_flags_decoder(
+ lzma_stream *strm, lzma_options_filter *options);
diff --git a/src/liblzma/api/lzma/index.h b/src/liblzma/api/lzma/index.h
new file mode 100644
index 00000000..7e59c4b3
--- /dev/null
+++ b/src/liblzma/api/lzma/index.h
@@ -0,0 +1,84 @@
+/**
+ * \file lzma/index.h
+ * \brief Handling of Index lists
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief
+ *
+ * FIXME desc
+ */
+typedef struct lzma_index_s lzma_index;
+struct lzma_index_s {
+ /**
+ * \brief Total Size of the Block
+ *
+ * This includes Block Header, Compressed Data, and Block Footer.
+ */
+ lzma_vli total_size;
+
+ /**
+ * \brief Uncompressed Size of the Block
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Pointer to the next Index Record
+ *
+ * This is NULL on the last Index Record.
+ */
+ lzma_index *next;
+};
+
+
+/**
+ * \brief Duplicates an Index list
+ *
+ * \return A copy of the Index list, or NULL if memory allocation
+ * failed or the original Index was empty.
+ */
+extern lzma_index *lzma_index_dup(
+ const lzma_index *index, lzma_allocator *allocator);
+
+
+/**
+ * \brief Frees an Index list
+ *
+ * All Index Recors in the list are freed. This function is convenient when
+ * getting rid of lzma_metadata structures containing an Index.
+ */
+extern void lzma_index_free(lzma_index *index, lzma_allocator *allocator);
+
+
+/**
+ * \brief Calculates information about the Index
+ *
+ * \return LZMA_OK on success, LZMA_PROG_ERROR on error. FIXME
+ */
+extern lzma_ret lzma_index_count(const lzma_index *index, size_t *count,
+ lzma_vli *lzma_restrict total_size,
+ lzma_vli *lzma_restrict uncompressed_size);
+
+
+/**
+ * \brief Compares if two Index lists are identical
+ */
+extern lzma_bool lzma_index_is_equal(const lzma_index *a, const lzma_index *b);
diff --git a/src/liblzma/api/lzma/info.h b/src/liblzma/api/lzma/info.h
new file mode 100644
index 00000000..3a91850f
--- /dev/null
+++ b/src/liblzma/api/lzma/info.h
@@ -0,0 +1,315 @@
+/**
+ * \file lzma/info.h
+ * \brief Handling of Stream size information
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**********
+ * Basics *
+ **********/
+
+/**
+ * \brief Opaque data type to hold the size information
+ */
+typedef struct lzma_info_s lzma_info;
+
+
+typedef struct {
+ /**
+ * \brief Total Size of this Block
+ *
+ * This can be LZMA_VLI_VALUE_UNKNOWN.
+ */
+ lzma_vli total_size;
+
+ /**
+ * \brief Uncompressed Size of this Block
+ *
+ * This can be LZMA_VLI_VALUE_UNKNOWN.
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Offset of the first byte of the Block
+ *
+ * In encoder, this is useful to find out the alignment of the Block.
+ *
+ * In decoder, this is useful when doing random-access reading
+ * with help from lzma_info_data_locate().
+ */
+ lzma_vli stream_offset;
+
+ /**
+ * \brief Uncompressed offset of the Block
+ *
+ * Offset of the first uncompressed byte of the Block relative to
+ * all uncompressed data in the Block.
+ * FIXME desc
+ */
+ lzma_vli uncompressed_offset;
+
+ /**
+ * \brief Pointers to internal data structures
+ *
+ * Applications must not touch these.
+ */
+ void *internal[4];
+
+} lzma_info_iter;
+
+
+typedef enum {
+ LZMA_INFO_STREAM_START,
+ LZMA_INFO_HEADER_METADATA,
+ LZMA_INFO_TOTAL,
+ LZMA_INFO_UNCOMPRESSED,
+ LZMA_INFO_FOOTER_METADATA
+} lzma_info_size;
+
+
+/**
+ * \brief Allocates and initializes a new lzma_info structure
+ *
+ * If info is NULL, a new lzma_info structure is allocated, initialized, and
+ * a pointer to it returned. If allocation fails, NULL is returned.
+ *
+ * If info is non-NULL, it is reinitialized and the same pointer returned.
+ * (In this case, return value cannot be NULL or a different pointer than
+ * the info given as argument.)
+ */
+extern lzma_info *lzma_info_init(lzma_info *info, lzma_allocator *allocator);
+
+
+/**
+ * \brief Resets lzma_info
+ *
+ * This is like calling lzma_info_end() and lzma_info_create(), but
+ * re-uses the existing base structure.
+ */
+extern void lzma_info_reset(
+ lzma_info *info, lzma_allocator *allocator);
+
+
+/**
+ * \brief Frees memory allocated for a lzma_info structure
+ */
+extern void lzma_info_free(lzma_info *info, lzma_allocator *allocator);
+
+
+/************************
+ * Setting known values *
+ ************************/
+
+/**
+ * \brief Set a known size value
+ *
+ * \param info Pointer returned by lzma_info_create()
+ * \param type Any value from lzma_info_size
+ * \param size Value to set or verify
+ *
+ * \return LZMA_OK on success, LZMA_DATA_ERROR if the size doesn't
+ * match the existing information, or LZMA_PROG_ERROR
+ * if type is invalid or size is not a valid VLI.
+ */
+extern lzma_ret lzma_info_size_set(
+ lzma_info *info, lzma_info_size type, lzma_vli size);
+
+
+/**
+ * \brief Sets the Index
+ *
+ * The given lzma_index list is "absorbed" by this function. The application
+ * must not access it after this function call, even if this function returns
+ * an error.
+ *
+ * \note The given lzma_index will at some point get freed by the
+ * lzma_info_* functions. If you use a custom lzma_allocator,
+ * make sure that it can free the lzma_index.
+ */
+extern lzma_ret lzma_info_index_set(
+ lzma_info *info, lzma_allocator *allocator,
+ lzma_index *index, lzma_bool eat_index);
+
+
+/**
+ * \brief Sets information from a known Metadata Block
+ *
+ * This is a shortcut for calling lzma_info_size_set() with different type
+ * arguments, lzma_info_index_set() with metadata->index.
+ */
+extern lzma_ret lzma_info_metadata_set(lzma_info *info,
+ lzma_allocator *allocator, lzma_metadata *metadata,
+ lzma_bool is_header_metadata, lzma_bool eat_index);
+
+
+/***************
+ * Incremental *
+ ***************/
+
+/**
+ * \brief Prepares an iterator to be used with given lzma_info structure
+ *
+ *
+ */
+extern void lzma_info_iter_begin(lzma_info *info, lzma_info_iter *iter);
+
+
+/**
+ * \brief Moves to the next Index Record
+ *
+ *
+ */
+extern lzma_ret lzma_info_iter_next(
+ lzma_info_iter *iter, lzma_allocator *allocator);
+
+
+/**
+ * \brief Sets or verifies the sizes in the Index Record
+ *
+ * \param iter Pointer to iterator to be set or verified
+ * \param total_size
+ * Total Size in bytes or LZMA_VLI_VALUE_UNKNOWN
+ * \param uncompressed_size
+ * Uncompressed Size or LZMA_VLI_VALUE_UNKNOWN
+ *
+ * \return - LZMA_OK: All OK.
+ * - LZMA_DATA_ERROR: Given sizes don't match with the already
+ * known sizes.
+ * - LZMA_PROG_ERROR: Internal error, possibly integer
+ * overflow (e.g. the sum of all the known sizes is too big)
+ */
+extern lzma_ret lzma_info_iter_set(lzma_info_iter *iter,
+ lzma_vli total_size, lzma_vli uncompressed_size);
+
+
+/**
+ * \brief Locates a Data Block
+ *
+ * \param iter Properly initialized iterator
+ * \param allocator Pointer to lzma_allocator or NULL
+ * \param uncompressed_offset
+ * Target offset to locate. The final offset
+ * will be equal or smaller than this.
+ * \param allow_alloc True if this function is allowed to call
+ * lzma_info_iter_next() to allocate a new Record
+ * if the requested offset reached end of Index
+ * Record list. Note that if Index has been marked
+ * final, lzma_info_iter_next() is never called.
+ *
+ * \return - LZMA_OK: All OK, *iter updated accordingly.
+ * - LZMA_DATA_ERROR: Trying to search past the end of the Index
+ * Record list, and allocating a new Record was not allowed
+ * either because allow_alloc was false or Index was final.
+ * - LZMA_PROG_ERROR: Internal error (probably integer
+ * overflow causing some lzma_vli getting too big).
+ */
+extern lzma_ret lzma_info_iter_locate(lzma_info_iter *iter,
+ lzma_allocator *allocator, lzma_vli uncompressed_offset,
+ lzma_bool allow_alloc);
+
+
+/**
+ * \brief Finishes incrementally constructed Index
+ *
+ * This sets the known Total Size and Uncompressed of the Data Blocks
+ * based on the information collected from the Index Records, and marks
+ * the Index as final.
+ */
+extern lzma_ret lzma_info_index_finish(lzma_info *info);
+
+
+/***************************
+ * Reading the information *
+ ***************************/
+
+/**
+ * \brief Gets a known size
+ *
+ *
+ */
+extern lzma_vli lzma_info_size_get(
+ const lzma_info *info, lzma_info_size type);
+
+extern lzma_vli lzma_info_metadata_locate(
+ const lzma_info *info, lzma_bool is_header_metadata);
+
+/**
+ * \brief Gets a pointer to the beginning of the Index list
+ *
+ * If detach is true, the Index will be detached from the lzma_info
+ * structure, and thus not be modified or freed by lzma_info_end().
+ *
+ * If detach is false, the application must not modify the Index in any way.
+ * Also, the Index list is guaranteed to be valid only till the next call
+ * to any lzma_info_* function.
+ */
+extern lzma_index *lzma_info_index_get(lzma_info *info, lzma_bool detach);
+
+
+extern size_t lzma_info_index_count_get(const lzma_info *info);
+
+
+extern uint32_t lzma_info_metadata_alignment_get(
+ const lzma_info *info, lzma_bool is_header_metadata);
+
+
+
+/**
+ * \brief Locate a Block containing the given uncompressed offset
+ *
+ * This function is useful when you need to do random-access reading in
+ * a Multi-Block Stream.
+ *
+ * \param info Pointer to lzma_info that has at least one
+ * Index Record. The Index doesn't need to be finished.
+ * \param uncompressed_target
+ * Uncompressed target offset which the caller would
+ * like to locate from the Stream.
+ * \param stream_offset
+ * Starting offset (relative to the beginning the Stream)
+ * of the Block containing the requested location.
+ * \param uncompressed_offset
+ * The actual uncompressed offset of the beginning of
+ * the Block. uncompressed_offset <= uncompressed_target
+ * is always true; the application needs to uncompress
+ * uncompressed_target - uncompressed_offset bytes to
+ * reach the requested target offset.
+ * \param total_size
+ * Total Size of the Block. If the Index is incomplete,
+ * this may be LZMA_VLI_VALUE_UNKNOWN indicating unknown
+ * size.
+ * \param uncompressed_size
+ * Uncompressed Size of the Block. If the Index is
+ * incomplete, this may be LZMA_VLI_VALUE_UNKNOWN
+ * indicating unknown size. The application must pass
+ * this value to the Block decoder to verify FIXME
+ *
+ * \return
+ *
+ * \note This function is currently implemented as a linear search.
+ * If there are many Index Records, this can be really slow.
+ * This can be improved in newer liblzma versions if needed.
+ */
+extern lzma_bool lzma_info_data_locate(const lzma_info *info,
+ lzma_vli uncompressed_target,
+ lzma_vli *lzma_restrict stream_offset,
+ lzma_vli *lzma_restrict uncompressed_offset,
+ lzma_vli *lzma_restrict total_size,
+ lzma_vli *lzma_restrict uncompressed_size);
diff --git a/src/liblzma/api/lzma/init.h b/src/liblzma/api/lzma/init.h
new file mode 100644
index 00000000..f7b79246
--- /dev/null
+++ b/src/liblzma/api/lzma/init.h
@@ -0,0 +1,85 @@
+/**
+ * \file lzma/init.h
+ * \brief Initializations
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Initialize all internal static variables
+ *
+ * Depending on the build options, liblzma may have some internal static
+ * variables, that must be initialized before using any other part of
+ * the library (*). It is recommended to do these initializations in the very
+ * beginning of the application by calling appropriate initialization function.
+ *
+ * (*) There are some exceptions to this rule. FIXME
+ *
+ * The initialization functions are not necessarily thread-safe, thus the
+ * required initializations must be done before creating any threads. (The
+ * rest of the functions of liblzma are thread-safe.) Calling the
+ * initialization functions multiple times does no harm, although it
+ * still shouldn't be done when there are multiple threads running.
+ *
+ * lzma_init() initializes all internal static variables by calling
+ * lzma_lzma_init_encoder() and lzma_init_decoder().
+ *
+ * If you need only encoder, decoder, or neither-encoder-nor-decoder
+ * functions, you may use other initialization functions, which initialize
+ * only a subset of liblzma's internal static variables. Using those
+ * functions have the following advantages:
+ * - When linking statically against liblzma, less useless functions will
+ * get linked into the binary. E.g. if you need only the decoder functions,
+ * using lzma_init_decoder() avoids linking bunch of encoder related code.
+ * - There is less things to initialize, making the initialization
+ * process slightly faster.
+ */
+extern void lzma_init(void);
+
+
+/**
+ * \brief Initialize internal static variables needed by encoders
+ *
+ * If you need only the encoder functions, you may use this function to
+ * initialize only the things required by encoders.
+ *
+ * This function also calls lzma_init_check().
+ */
+extern void lzma_init_encoder(void);
+
+
+/**
+ * \brief Initialize internal static variables needed by decoders
+ *
+ * If you need only the decoder functions, you may use this function to
+ * initialize only the things required by decoders.
+ *
+ * This function also calls lzma_init_check().
+ */
+extern void lzma_init_decoder(void);
+
+
+/**
+ * \brief Initialize internal static variables needed by integrity checks
+ *
+ * Currently this initializes CRC32 and CRC64 lookup tables if precalculated
+ * tables haven't been built into the library. This function can be useful
+ * if the only thing you need from liblzma is the integrity check functions.
+ */
+extern void lzma_init_check(void);
diff --git a/src/liblzma/api/lzma/lzma.h b/src/liblzma/api/lzma/lzma.h
new file mode 100644
index 00000000..0fe74854
--- /dev/null
+++ b/src/liblzma/api/lzma/lzma.h
@@ -0,0 +1,312 @@
+/**
+ * \file lzma/lzma.h
+ * \brief LZMA filter
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter ID
+ *
+ * Filter ID of the LZMA filter. This is used as lzma_options_filter.id.
+ */
+#define LZMA_FILTER_LZMA LZMA_VLI_C(0x40)
+
+
+/**
+ * \brief LZMA compression modes
+ *
+ * Currently there are only two modes. Earlier LZMA SDKs had also third
+ * mode between fast and best.
+ */
+typedef enum {
+ LZMA_MODE_INVALID = -1,
+ /**<
+ * \brief Invalid mode
+ *
+ * Used as array terminator in lzma_available_modes.
+ */
+
+
+ LZMA_MODE_FAST = 0,
+ /**<
+ * \brief Fast compression
+ *
+ * Fast mode is usually at its best when combined with
+ * a hash chain match finder.
+ */
+
+ LZMA_MODE_BEST = 2
+ /**<
+ * \brief Best compression ratio
+ *
+ * This is usually notably slower than fast mode. Use this
+ * together with binary tree match finders to expose the
+ * full potential of the LZMA encoder.
+ */
+} lzma_mode;
+
+
+/**
+ * \brief Match finders
+ *
+ * Match finder has major effect on both speed and compression ratio.
+ * Usually hash chains are faster than binary trees.
+ */
+typedef enum {
+ LZMA_MF_INVALID = -1,
+ /**<
+ * \brief Invalid match finder ID
+ *
+ * Used as array terminator in lzma_available_match_finders.
+ */
+
+ LZMA_MF_HC3 = 0x03,
+ /**<
+ * \brief Hash Chain with 3 bytes hashing
+ *
+ * \todo Memory requirements
+ *
+ * \note It's possible that this match finder gets
+ * removed in future. The definition will stay
+ * in this header, but liblzma may return
+ * LZMA_HEADER_ERROR if it is specified (just
+ * like it would if the match finder had been
+ * disabled at compile time).
+ */
+
+ LZMA_MF_HC4 = 0x04,
+ /**<
+ * \brief Hash Chain with 4 bytes hashing
+ *
+ * Memory requirements: 7.5 * dictionary_size + 4 MiB
+ *
+ * \note It's possible that this match finder gets
+ * removed in future. The definition will stay
+ * in this header, but liblzma may return
+ * LZMA_HEADER_ERROR if it is specified (just
+ * like it would if the match finder had been
+ * disabled at compile time).
+ */
+
+ LZMA_MF_BT2 = 0x12,
+ /**<
+ * \brief Binary Tree with 2 bytes hashing
+ *
+ * Memory requirements: 9.5 * dictionary_size + 4 MiB
+ */
+
+ LZMA_MF_BT3 = 0x13,
+ /**<
+ * \brief Binary Tree with 3 bytes hashing
+ *
+ * Memory requirements: 11.5 * dictionary_size + 4 MiB
+ */
+
+ LZMA_MF_BT4 = 0x14
+ /**<
+ * \brief Binary Tree with 4 bytes hashing
+ *
+ * Memory requirements: 11.5 * dictionary_size + 4 MiB
+ */
+} lzma_match_finder;
+
+
+/**
+ * \brief Options specific to the LZMA method handler
+ */
+typedef struct {
+ /**********************************
+ * LZMA encoding/decoding options *
+ **********************************/
+
+ /* These options are required in encoder and also with raw decoding. */
+
+ /**
+ * \brief Dictionary size in bytes
+ *
+ * Dictionary size indicates how many bytes of the recently processed
+ * uncompressed data is kept in memory. One method to reduce size of
+ * the uncompressed data is to store distance-length pairs, which
+ * indicate what data to repeat from the dictionary buffer. Thus,
+ * the bigger the dictionary, the better compression ratio usually is.
+ *
+ * Raw decoding: Too big dictionary does no other harm than
+ * wasting memory. This value is ignored by lzma_raw_decode_buffer(),
+ * because it uses the target buffer as the dictionary.
+ */
+ uint32_t dictionary_size;
+# define LZMA_DICTIONARY_SIZE_MIN 1
+# define LZMA_DICTIONARY_SIZE_MAX (UINT32_C(1) << 30)
+# define LZMA_DICTIONARY_SIZE_DEFAULT (UINT32_C(1) << 23)
+
+ /**
+ * \brief Number of literal context bits
+ *
+ * How many of the highest bits of the previous uncompressed
+ * eight-bit byte (also known as `literal') are taken into
+ * account when predicting the bits of the next literal.
+ *
+ * \todo Example
+ */
+ uint32_t literal_context_bits;
+# define LZMA_LITERAL_CONTEXT_BITS_MIN 0
+# define LZMA_LITERAL_CONTEXT_BITS_MAX 8
+# define LZMA_LITERAL_CONTEXT_BITS_DEFAULT 3
+
+ /**
+ * \brief Number of literal position bits
+ *
+ * How many of the lowest bits of the current position (number
+ * of bytes from the beginning of the uncompressed data) in the
+ * uncompressed data is taken into account when predicting the
+ * bits of the next literal (a single eight-bit byte).
+ *
+ * \todo Example
+ */
+ uint32_t literal_pos_bits;
+# define LZMA_LITERAL_POS_BITS_MIN 0
+# define LZMA_LITERAL_POS_BITS_MAX 4
+# define LZMA_LITERAL_POS_BITS_DEFAULT 0
+
+ /**
+ * \brief Number of position bits
+ *
+ * How many of the lowest bits of the current position in the
+ * uncompressed data is taken into account when estimating
+ * probabilities of matches. A match is a sequence of bytes for
+ * which a matching sequence is found from the dictionary and
+ * thus can be stored as distance-length pair.
+ *
+ * Example: If most of the matches occur at byte positions
+ * of 8 * n + 3, that is, 3, 11, 19, ... set pos_bits to 3,
+ * because 2**3 == 8.
+ */
+ uint32_t pos_bits;
+# define LZMA_POS_BITS_MIN 0
+# define LZMA_POS_BITS_MAX 4
+# define LZMA_POS_BITS_DEFAULT 2
+
+ /**
+ * \brief Pointer to an initial dictionary
+ *
+ * It is possible to initialize the LZ77 history window using
+ * a preset dictionary. Here is a good quote from zlib's
+ * documentation; this applies to LZMA as is:
+ *
+ * "The dictionary should consist of strings (byte sequences) that
+ * are likely to be encountered later in the data to be compressed,
+ * with the most commonly used strings preferably put towards the
+ * end of the dictionary. Using a dictionary is most useful when
+ * the data to be compressed is short and can be predicted with
+ * good accuracy; the data can then be compressed better than
+ * with the default empty dictionary."
+ * (From deflateSetDictionary() in zlib.h of zlib version 1.2.3)
+ *
+ * This feature should be used only in special situations.
+ * It works correctly only with raw encoding and decoding.
+ * Currently none of the container formats supported by
+ * liblzma allow preset dictionary when decoding, thus if
+ * you create a .lzma file with preset dictionary, it cannot
+ * be decoded with the regular .lzma decoder functions.
+ *
+ * \todo This feature is not implemented yet.
+ */
+ const uint8_t *preset_dictionary;
+
+ /**
+ * \brief Size of the preset dictionary
+ *
+ * Specifies the size of the preset dictionary. If the size is
+ * bigger than dictionary_size, only the last dictionary_size
+ * bytes are processed.
+ *
+ * This variable is read only when preset_dictionary is not NULL.
+ */
+ uint32_t preset_dictionary_size;
+
+ /******************************************
+ * LZMA options needed only when encoding *
+ ******************************************/
+
+ /** LZMA compression mode */
+ lzma_mode mode;
+
+ /**
+ * \brief Number of fast bytes
+ *
+ * Number of fast bytes determines how many bytes the encoder
+ * compares from the match candidates when looking for the best
+ * match. Bigger fast bytes value usually increase both compression
+ * ratio and time.
+ */
+ uint32_t fast_bytes;
+# define LZMA_FAST_BYTES_MIN 5
+# define LZMA_FAST_BYTES_MAX 273
+# define LZMA_FAST_BYTES_DEFAULT 128
+
+ /** Match finder ID */
+ lzma_match_finder match_finder;
+
+ /**
+ * \brief Match finder cycles
+ *
+ * Higher values give slightly better compression ratio but
+ * decrease speed. Use special value 0 to let liblzma use
+ * match-finder-dependent default value.
+ *
+ * \todo Write much better description.
+ */
+ uint32_t match_finder_cycles;
+
+} lzma_options_lzma;
+
+
+/**
+ * \brief Available LZMA encoding modes
+ *
+ * Pointer to an array containing the list of available encoding modes.
+ *
+ * This variable is available only if LZMA encoder has been enabled.
+ */
+extern const lzma_mode *const lzma_available_modes;
+
+
+/**
+ * \brief Available match finders
+ *
+ * Pointer to an array containing the list of available match finders.
+ * The last element is LZMA_MF_INVALID.
+ *
+ * This variable is available only if LZMA encoder has been enabled.
+ */
+extern const lzma_match_finder *const lzma_available_match_finders;
+
+
+/**
+ * \brief Table of presets for the LZMA filter
+ *
+ * lzma_presets[0] is the fastest and lzma_preset_lzma[8] is the slowest.
+ * These presets match the switches -1 .. -9 of the lzma command line tool
+ *
+ * The preset values are subject to changes between liblzma versions.
+ *
+ * This variable is available only if LZMA encoder has been enabled.
+ */
+extern const lzma_options_lzma lzma_preset_lzma[9];
diff --git a/src/liblzma/api/lzma/memlimit.h b/src/liblzma/api/lzma/memlimit.h
new file mode 100644
index 00000000..26ec50fe
--- /dev/null
+++ b/src/liblzma/api/lzma/memlimit.h
@@ -0,0 +1,157 @@
+/**
+ * \file lzma/memlimit.h
+ * \brief Memory usage limitter
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Opaque data type used with the memory usage limitting functions
+ */
+typedef struct lzma_memlimit_s lzma_memlimit;
+
+
+/**
+ * \brief Allocates and initializes a new lzma_memlimit structure
+ *
+ * It is easy to make liblzma to use huge amounts of memory. This can
+ * be a problem especially with the decoder, since it a file requiring
+ * huge amounts of memory to uncompress could allow even a denial of
+ * service attack if the memory usage wasn't limited.
+ *
+ * liblzma provides a set of functions to control memory usage. Pointers
+ * to these functions can be used in lzma_allocator structure, which makes
+ * it easy to limit memory usage with liblzma.
+ *
+ * The memory limitter functions are not tied to limitting memory usage
+ * with liblzma itself. You can use them with anything you like.
+ *
+ * In multi-threaded applications, only one thread at once may use the same
+ * lzma_memlimit structure. If there is a need, this limitation may
+ * be removed in future versions without breaking the libary API/ABI.
+ *
+ * \param limit Initial memory usage limit in bytes
+ *
+ * \return Pointer to allocated and initialized lzma_memlimit
+ * structure. On error, NULL is returned. The reason behind
+ * an error is either that malloc() failed or that the given
+ * limit was so small that it didn't allow allocating even
+ * the lzma_memlimit structure itself.
+ *
+ * \note Excluding lzma_memlimit_usage(), the functions whose name begin
+ * lzma_memlimit_ can be used even if lzma_init() hasn't been
+ * called.
+ */
+extern lzma_memlimit *lzma_memlimit_create(size_t limit);
+
+
+/**
+ * \brief Sets a new memory usage limit
+ *
+ * \param mem Pointer to a lzma_memlimit structure returned
+ * earlier by lzma_memry_limit_create().
+ * \param limit New memory usage limit
+ *
+ * The new usage limit may be smaller than the amount of memory currently
+ * allocated via *mem: New allocations will fail until enough memory has
+ * been freed or a new limit is set, but the existing allocatations will
+ * stay untouched.
+ */
+extern void lzma_memlimit_set(lzma_memlimit *mem, size_t limit);
+
+
+/**
+ * \brief Gets the current memory usage limit
+ */
+extern size_t lzma_memlimit_get(const lzma_memlimit *mem);
+
+
+/**
+ * \brief Gets the amount of currently allocated memory
+ *
+ * \note This value includes the sizes of some helper structures,
+ * thus it will always be larger than the total number of
+ * bytes allocated via lzma_memlimit_alloc().
+ */
+extern size_t lzma_memlimit_used(const lzma_memlimit *mem);
+
+
+/**
+ * \brief Allocates memory with malloc() if memory limit allows
+ *
+ * \param mem Pointer to a lzma_memlimit structure returned
+ * earlier by lzma_memry_limit_create().
+ * \param nmemb Number of elements to allocate. While liblzma always
+ * sets this to one, this function still takes the
+ * value of nmemb into account to keep the function
+ * usable with zlib and libbzip2.
+ * \param size Size of an element.
+ *
+ * \return Pointer to memory allocated with malloc(nmemb * size),
+ * except if nmemb * size == 0 which returns malloc(1).
+ * On error, NULL is returned.
+ *
+ * \note This function assumes that nmemb * size is at maximum of
+ * SIZE_MAX. If it isn't, an overflow will occur resulting
+ * invalid amount of memory being allocated.
+ */
+extern void *lzma_memlimit_alloc(
+ lzma_memlimit *mem, size_t nmemb, size_t size);
+
+
+/**
+ * \brief Removes the pointer from memory limitting list
+ *
+ * \param mem Pointer to a lzma_memlimit structure returned
+ * earlier by lzma_memry_limit_create().
+ * \param ptr Pointer returned earlier by lzma_memlimit_alloc().
+ *
+ * This function removes ptr from the internal list and decreases the
+ * counter of used memory accordingly. The ptr itself isn't freed. This is
+ * useful when Extra Records allocated by liblzma using lzma_memlimit
+ * are needed by the application and must not be freed when the
+ * lzma_memlimit structure is destroyed.
+ *
+ * It is OK to call this function with ptr that hasn't been allocated with
+ * lzma_memlimit_alloc(). In that case, this has no effect other than wasting
+ * a few CPU cycles.
+ */
+extern void lzma_memlimit_detach(lzma_memlimit *mem, void *ptr);
+
+
+/**
+ * \brief Frees memory and updates the memory limit list
+ *
+ * This is like lzma_memlimit_detach() but also frees the given pointer.
+ */
+extern void lzma_memlimit_free(lzma_memlimit *mem, void *ptr);
+
+
+/**
+ * \brief Frees the memory allocated for and by the memory usage limitter
+ *
+ * \param mem Pointer to memory limitter
+ * \param free_allocated If this is non-zero, all the memory allocated
+ * by lzma_memlimit_alloc() using *mem is also
+ * freed if it hasn't already been freed with
+ * lzma_memlimit_free(). Usually this should be
+ * set to true.
+ */
+extern void lzma_memlimit_end(
+ lzma_memlimit *mem, lzma_bool free_allocated);
diff --git a/src/liblzma/api/lzma/metadata.h b/src/liblzma/api/lzma/metadata.h
new file mode 100644
index 00000000..69592a3a
--- /dev/null
+++ b/src/liblzma/api/lzma/metadata.h
@@ -0,0 +1,100 @@
+/**
+ * \file lzma/metadata.h
+ * \brief Metadata handling
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Information stored into a Metadata Block
+ *
+ * This structure holds all the information that can be stored to
+ * a Metadata Block.
+ */
+typedef struct {
+ /**
+ * \brief Size of Header Metadata Block
+ */
+ lzma_vli header_metadata_size;
+
+ /**
+ * \brief Total Size of the Stream
+ */
+ lzma_vli total_size;
+
+ /**
+ * \brief Uncompressed Size of the Stream
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Index of the Blocks stored in the Stream
+ */
+ lzma_index *index;
+
+ /**
+ * \brief Extra information
+ */
+ lzma_extra *extra;
+
+} lzma_metadata;
+
+
+/**
+ * \brief Calculate the encoded size of Metadata
+ *
+ * \return Uncompressed size of the Metadata in encoded form. This value
+ * may be passed to Block encoder as Uncompressed Size when using
+ * Metadata filter. On error, zero is returned.
+ */
+extern lzma_vli lzma_metadata_size(const lzma_metadata *metadata);
+
+
+/**
+ * \brief Initializes Metadata encoder
+ *
+ * \param coder Pointer to a pointer to hold Metadata encoder's
+ * internal state. Original value is ignored, thus
+ * you don't need to initialize the pointer.
+ * \param allocator Custom memory allocator; usually NULL.
+ * \param metadata Pointer to Metadata to encoded
+ *
+ * \return - LZMA_OK: Initialization succeeded.
+ * - LZMA_MEM_ERROR: Cannot allocate memory for *coder.
+ *
+ * The initialization function makes internal copy of the *metadata structure.
+ * However, the linked lists metadata->index and metadata->extra are NOT
+ * copied. Thus, the application may destroy *metadata after initialization
+ * if it likes, but not Index or Extra.
+ */
+extern lzma_ret lzma_metadata_encoder(lzma_stream *strm,
+ lzma_options_block *options, const lzma_metadata *metadata);
+
+
+/**
+ * \brief Initializes Metadata decoder
+ *
+ * \param want_extra If this is true, Extra Records will be stored
+ * to metadata->extra. If this is false, Extra
+ * Records will be parsed but not stored anywhere,
+ * metadata->extra will be set to NULL.
+ */
+extern lzma_ret lzma_metadata_decoder(
+ lzma_stream *strm, lzma_options_block *options,
+ lzma_metadata *metadata, lzma_bool want_extra);
diff --git a/src/liblzma/api/lzma/raw.h b/src/liblzma/api/lzma/raw.h
new file mode 100644
index 00000000..c1ee41d8
--- /dev/null
+++ b/src/liblzma/api/lzma/raw.h
@@ -0,0 +1,72 @@
+/**
+ * \file lzma/raw.h
+ * \brief Raw encoder and decoder
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Initializes raw encoder
+ *
+ * This function may be useful when implementing custom file formats.
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param options Array of lzma_options_filter structures.
+ * The end of the array must be marked with
+ * .id = LZMA_VLI_VALUE_UNKNOWN. The minimum
+ * number of filters is zero; the maximum is
+ * determined by available memory.
+ * \param uncompressed_size
+ * Size of the uncompressed data. If it is unknown,
+ * use LZMA_VLI_VALUE_UNKNOWN. You need to give the
+ * same value to the raw decoder to decode the data.
+ * \param allow_implicit
+ * If true, an implicit Copy or Subblock filter should be
+ * automatically added when needed. If this is false and
+ * an implicit filter would be needed, LZMA_PROG_ERROR is
+ * returned.
+ *
+ * The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
+ * filter chain support it), or LZMA_FINISH.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_HEADER_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_raw_encoder(
+ lzma_stream *strm, const lzma_options_filter *options,
+ lzma_vli uncompressed_size, lzma_bool allow_implicit);
+
+
+/**
+ * \brief Initializes raw decoder
+ *
+ * The initialization of raw decoder goes similarly to raw encoder.
+ *
+ * The `action' with lzma_code() can be LZMA_RUN or LZMA_SYNC_FLUSH.
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_HEADER_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_raw_decoder(
+ lzma_stream *strm, const lzma_options_filter *options,
+ lzma_vli uncompressed_size, lzma_bool allow_implicit);
diff --git a/src/liblzma/api/lzma/simple.h b/src/liblzma/api/lzma/simple.h
new file mode 100644
index 00000000..fb78d01f
--- /dev/null
+++ b/src/liblzma/api/lzma/simple.h
@@ -0,0 +1,85 @@
+/**
+ * \file lzma/simple.h
+ * \brief So called "simple" filters
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/* Filter IDs for lzma_options_filter.id */
+
+#define LZMA_FILTER_X86 LZMA_VLI_C(0x04)
+ /**<
+ * BCJ (Branch, Call, Jump) filter for x86 binaries
+ */
+
+#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05)
+ /**<
+ * Filter for Big endian PowerPC binaries
+ */
+
+#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06)
+ /**<
+ * Filter for IA64 (Itanium) binaries.
+ */
+
+#define LZMA_FILTER_ARM LZMA_VLI_C(0x07)
+ /**<
+ * Filter for ARM binaries.
+ */
+
+#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08)
+ /**<
+ * Filter for ARMThumb binaries.
+ */
+
+#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09)
+ /**<
+ * Filter for SPARC binaries.
+ */
+
+
+/**
+ * \brief Options for so called "simple" filters
+ *
+ * The simple filters never change the size of the data. Specifying options
+ * for them is optional: if pointer to options is NULL, default values are
+ * used. You probably never need to specify these options, so just set the
+ * options pointer to NULL and be happy.
+ *
+ * If options with non-default values have been specified when encoding,
+ * the same options must also be specified when decoding.
+ */
+typedef struct {
+ /**
+ * \brief Start offset for branch conversions
+ *
+ * This setting is useful only when the same filter is used
+ * _separately_ for multiple sections of the same executable file,
+ * and the sections contain cross-section branch/call/jump
+ * instructions. In that case it is benefical to set the start
+ * offset of the non-first sections so that the relative addresses
+ * of the cross-section branch/call/jump instructions will use the
+ * same absolute addresses as in the first section.
+ *
+ * When the pointer to options is NULL, the default value is used.
+ * The default value is zero.
+ */
+ uint32_t start_offset;
+
+} lzma_options_simple;
diff --git a/src/liblzma/api/lzma/stream.h b/src/liblzma/api/lzma/stream.h
new file mode 100644
index 00000000..be86075f
--- /dev/null
+++ b/src/liblzma/api/lzma/stream.h
@@ -0,0 +1,178 @@
+/**
+ * \file lzma/stream.h
+ * \brief .lzma Stream handling
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Options for .lzma Stream encoder
+ */
+typedef struct {
+ /**
+ * \brief Type of integrity Check
+ *
+ * The type of the integrity Check is stored into Stream Header
+ * and Stream Footer. The same Check is used for all Blocks in
+ * the Stream.
+ */
+ lzma_check_type check;
+
+ /**
+ * \brief Precense of CRC32 of the Block Header
+ *
+ * Set this to true if CRC32 of every Block Header should be
+ * calculated and stored in the Block Header. This is recommended.
+ *
+ * This setting is stored into Stream Header and Stream Footer.
+ */
+ lzma_bool has_crc32;
+
+ /**
+ * \brief Uncompressed Size in bytes
+ *
+ * This is somewhat advanced feature. Most users want to set this to
+ * LZMA_VLI_VALUE_UNKNOWN to indicate unknown Uncompressed Size.
+ *
+ * If the Uncompressed Size of the Stream being encoded is known,
+ * it can be stored to the beginning of the Stream. The details
+ * differ for Single-Block and Multi-Block Streams:
+ * - With Single-Block Streams, the Uncompressed Size is stored to
+ * the Block Header and End of Payload Marker is omitted.
+ * - With Multi-Block Streams, the Uncompressed Size is stored to
+ * the Header Metadata Block. The Uncompressed Size of the Blocks
+ * will be unknown, because liblzma cannot predict how the
+ * application is going to split the data in Blocks.
+ */
+ lzma_vli uncompressed_size;
+
+ /**
+ * \brief Alignment of the beginning of the Stream
+ *
+ * Certain filters handle data in bigger chunks than single bytes.
+ * This affects two things:
+ * - Performance: aligned memory access is usually faster.
+ * - Further compression ratio in custom file formats: if you
+ * encode multiple Blocks with some non-compression filter
+ * such as LZMA_FILTER_POWERPC, it is a good idea to keep
+ * the inter-Block alignment correct to maximize compression
+ * ratio when all these Blocks are finally compressed as a
+ * single step.
+ *
+ * Usually the Stream is stored into its own file, thus
+ * the alignment is usually zero.
+ */
+ uint32_t alignment;
+
+ /**
+ * \brief Array of filters used to encode Data Blocks
+ *
+ * There can be at maximum of seven filters. The end of the array is
+ * marked with .id = LZMA_VLI_VALUE_UNKNOWN. (That's why the array
+ * has eight members.) Minimum number of filters is zero; in that
+ * case, an implicit Copy filter is used.
+ */
+ lzma_options_filter filters[8];
+
+ /**
+ * \brief Array of filters used to encode Metadata Blocks
+ *
+ * This is like filters[] but for Metadata Blocks. If Metadata
+ * Blocks are compressed, they usually are compressed with
+ * settings that require only little memory to uncompress e.g.
+ * LZMA with 64 KiB dictionary.
+ *
+ * \todo Recommend a preset.
+ *
+ * When liblzma sees that the Metadata Block would be very small
+ * even in uncompressed form, it is not compressed no matter
+ * what filter have been set here. This is to avoid possibly
+ * increasing the size of the Metadata Block with bad compression,
+ * and to avoid useless overhead of filters in uncompression phase.
+ */
+ lzma_options_filter metadata_filters[8];
+
+ /**
+ * \brief Extra information in the Header Metadata Block
+ */
+ lzma_extra *header;
+
+ /**
+ * \brief Extra information in the Footer Metadata Block
+ *
+ * It is enough to set this pointer any time before calling
+ * lzma_code() with LZMA_FINISH as the second argument.
+ */
+ lzma_extra *footer;
+
+} lzma_options_stream;
+
+
+/**
+ * \brief Initializes Single-Block .lzma Stream encoder
+ *
+ * This is the function that most developers are looking for. :-) It
+ * compresses using the specified options without storing any extra
+ * information.
+ *
+ * \todo Describe that is_metadata is ignored, maybe something else.
+ */
+extern lzma_ret lzma_stream_encoder_single(
+ lzma_stream *strm, const lzma_options_stream *options);
+
+
+/**
+ * \brief Initializes Multi-Block .lzma Stream encoder
+ *
+ */
+extern lzma_ret lzma_stream_encoder_multi(
+ lzma_stream *strm, const lzma_options_stream *options);
+
+
+/**
+ * \brief Initializes decoder for .lzma Stream
+ *
+ * \param strm Pointer to propertily prepared lzma_stream
+ * \param header Pointer to hold a pointer to Extra Records read
+ * from the Header Metadata Block. Use NULL if
+ * you don't care about Extra Records.
+ * \param footer Same as header, but for Footer Metadata Block.
+ *
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR: Cannot allocate memory.
+ *
+ * If header and/or footer are not NULL, *header and/or *footer will be
+ * initially set to NULL.
+ *
+ * The application can detect that Header Metadata Block has been completely
+ * parsed when the decoder procudes some output the first time. If *header
+ * is still NULL, there was no Extra field in the Header Metadata Block (or
+ * the whole Header Metadata Block wasn't present at all).
+ *
+ * The application can detect that Footer Metadata Block has been parsed
+ * completely when lzma_code() returns LZMA_STREAM_END. If *footer is still
+ * NULL, there was no Extra field in the Footer Metadata Block.
+ *
+ * \note If you use lzma_memory_limitter, the Extra Records will be
+ * allocated with it, and thus remain in the lzma_memory_limitter
+ * even after they get exported to the application via *header
+ * and *footer pointers.
+ */
+extern lzma_ret lzma_stream_decoder(lzma_stream *strm,
+ lzma_extra **header, lzma_extra **footer);
diff --git a/src/liblzma/api/lzma/stream_flags.h b/src/liblzma/api/lzma/stream_flags.h
new file mode 100644
index 00000000..070c91c9
--- /dev/null
+++ b/src/liblzma/api/lzma/stream_flags.h
@@ -0,0 +1,142 @@
+/**
+ * \file lzma/stream_flags.h
+ * \brief .lzma Stream Header and Stream tail encoder and decoder
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Size of Stream Header
+ *
+ * Magic Bytes (6) + Stream Flags (1) + CRC32 (4)
+ */
+#define LZMA_STREAM_HEADER_SIZE (6 + 1 + 4)
+
+
+/**
+ * \brief Size of Stream tail
+ *
+ * Because Stream Footer already has a defined meaning in the file format
+ * specification, we use Stream tail to denote these two fields:
+ * Stream Flags (1) + Magic Bytes (2)
+ */
+#define LZMA_STREAM_TAIL_SIZE (1 + 2)
+
+
+/**
+ * Options for encoding and decoding Stream Header and Stream tail
+ */
+typedef struct {
+ /**
+ * Type of the Check calculated from uncompressed data
+ */
+ lzma_check_type check;
+
+ /**
+ * True if Block Headers have the CRC32 field. Note that the CRC32
+ * field is always present in the Stream Header.
+ */
+ lzma_bool has_crc32;
+
+ /**
+ * True if the Stream is a Multi-Block Stream.
+ */
+ lzma_bool is_multi;
+
+} lzma_stream_flags;
+
+
+#define lzma_stream_flags_is_equal(a, b) \
+ ((a).check == (b).check \
+ && (a).has_crc32 == (b).has_crc32 \
+ && (a).is_multi == (b).is_multi)
+
+
+/**
+ * \brief Encodes Stream Header
+ *
+ * Encoding of the Stream Header is done with a single call instead of
+ * first initializing and then doing the actual work with lzma_code().
+ *
+ * \param out Beginning of the output buffer
+ * \param out_pos out[*out_pos] is the next write position. This
+ * is updated by the encoder.
+ * \param out_size out[out_size] is the first byte to not write.
+ * \param options Stream Header options to be encoded.
+ *
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_PROG_ERROR: Invalid options.
+ * - LZMA_BUF_ERROR: Not enough output buffer space.
+ */
+extern lzma_ret lzma_stream_header_encode(
+ uint8_t *out, const lzma_stream_flags *options);
+
+
+/**
+ * \brief Encodes Stream tail
+ *
+ * \param footer Pointer to a pointer that will hold the
+ * allocated buffer. Caller must free it once
+ * it isn't needed anymore.
+ * \param footer_size Pointer to a variable that will the final size
+ * of the footer buffer.
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc().
+ * \param options Stream Header options to be encoded.
+ *
+ * \return - LZMA_OK: Success; *header and *header_size set.
+ * - LZMA_PROG_ERROR: *options is invalid.
+ * - LZMA_MEM_ERROR: Cannot allocate memory.
+ */
+extern lzma_ret lzma_stream_tail_encode(
+ uint8_t *out, const lzma_stream_flags *options);
+
+
+/**
+ * \brief Initializes Stream Header decoder
+ *
+ * \param strm Pointer to lzma_stream used to pass input data
+ * \param options Target structure for parsed results
+ *
+ * \return - LZMA_OK: Successfully initialized
+ * - LZMA_MEM_ERROR: Cannot allocate memory
+ *
+ * The actual decoding is done with lzma_code() and freed with lzma_end().
+ */
+extern lzma_ret lzma_stream_header_decoder(
+ lzma_stream *strm, lzma_stream_flags *options);
+
+
+/**
+ * \brief Initializes Stream tail decoder
+ *
+ * \param strm Pointer to lzma_stream used to pass input data
+ * \param options Target structure for parsed results.
+ * \param decode_uncompressed_size
+ * Set to true if the first field to decode is
+ * Uncompressed Size. Set to false if the first
+ * field to decode is Backward Size.
+ *
+ * \return - LZMA_OK: Successfully initialized
+ * - LZMA_MEM_ERROR: Cannot allocate memory
+ *
+ * The actual decoding is done with lzma_code() and freed with lzma_end().
+ */
+extern lzma_ret lzma_stream_tail_decoder(
+ lzma_stream *strm, lzma_stream_flags *options);
diff --git a/src/liblzma/api/lzma/subblock.h b/src/liblzma/api/lzma/subblock.h
new file mode 100644
index 00000000..0474b6af
--- /dev/null
+++ b/src/liblzma/api/lzma/subblock.h
@@ -0,0 +1,197 @@
+/**
+ * \file lzma/subblock.h
+ * \brief Subblock filter
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Filter ID
+ *
+ * Filter ID of the Subblock filter. This is used as lzma_options_filter.id.
+ */
+#define LZMA_FILTER_SUBBLOCK LZMA_VLI_C(0x01)
+
+
+/**
+ * \brief Subfilter mode
+ *
+ * See lzma_options_subblock.subfilter_mode for details.
+ */
+typedef enum {
+ LZMA_SUBFILTER_NONE,
+ /**<
+ * No Subfilter is in use.
+ */
+
+ LZMA_SUBFILTER_SET,
+ /**<
+ * New Subfilter has been requested to be initialized.
+ */
+
+ LZMA_SUBFILTER_RUN,
+ /**<
+ * Subfilter is active.
+ */
+
+ LZMA_SUBFILTER_FINISH
+ /**<
+ * Subfilter has been requested to be finished.
+ */
+} lzma_subfilter_mode;
+
+
+/**
+ * \brief Options for the Subblock filter
+ *
+ * Specifying options for the Subblock filter is optional: if the pointer
+ * options is NULL, no subfilters are allowed and the default value is used
+ * for subblock_data_size.
+ */
+typedef struct {
+ /* Options for encoder and decoder */
+
+ /**
+ * \brief Allowing subfilters
+ *
+ * If this true, subfilters are allowed.
+ *
+ * In the encoder, if this is set to false, subfilter_mode and
+ * subfilter_options are completely ignored.
+ */
+ lzma_bool allow_subfilters;
+
+ /* Options for encoder only */
+
+ /**
+ * \brief Alignment
+ *
+ * The Subblock filter encapsulates the input data into Subblocks.
+ * Each Subblock has a header which takes a few bytes of space.
+ * When the output of the Subblock encoder is fed to another filter
+ * that takes advantage of the alignment of the input data (e.g. LZMA),
+ * the Subblock filter can add padding to keep the actual data parts
+ * in the Subblocks aligned correctly.
+ *
+ * The alignment should be a positive integer. Subblock filter will
+ * add enough padding between Subblocks so that this is true for
+ * every payload byte:
+ * input_offset % alignment == output_offset % alignment
+ *
+ * The Subblock filter assumes that the first output byte will be
+ * written to a position in the output stream that is properly aligned.
+ *
+ * FIXME desc
+ */
+ uint32_t alignment;
+# define LZMA_SUBBLOCK_ALIGNMENT_MIN 1
+# define LZMA_SUBBLOCK_ALIGNMENT_MAX 32
+# define LZMA_SUBBLOCK_ALIGNMENT_DEFAULT 4
+
+ /**
+ * \brief Size of the Subblock Data part of each Subblock
+ *
+ * This value is re-read every time a new Subblock is started.
+ *
+ * Bigger values
+ * - save a few bytes of space;
+ * - increase latency in the encoder (but no effect for decoding);
+ * - decrease memory locality (increased cache pollution) in the
+ * encoder (no effect in decoding).
+ */
+ uint32_t subblock_data_size;
+# define LZMA_SUBBLOCK_DATA_SIZE_MIN 1
+# define LZMA_SUBBLOCK_DATA_SIZE_MAX (UINT32_C(1) << 28)
+# define LZMA_SUBBLOCK_DATA_SIZE_DEFAULT 4096
+
+ /**
+ * \brief Run-length encoder remote control
+ *
+ * The Subblock filter has an internal run-length encoder (RLE). It
+ * can be useful when the data includes byte sequences that repeat
+ * very many times. The RLE can be used also when a Subfilter is
+ * in use; the RLE will be applied to the output of the Subfilter.
+ *
+ * Note that in contrast to traditional RLE, this RLE is intended to
+ * be used only when there's a lot of data to be repeated. If the
+ * input data has e.g. 500 bytes of NULs now and then, this RLE
+ * is probably useless, because plain LZMA should provide better
+ * results.
+ *
+ * Due to above reasons, it was decided to keep the implementation
+ * of the RLE very simple. When the rle variable is non-zero, it
+ * subblock_data_size must be a multiple of rle. Once the Subblock
+ * encoder has got subblock_data_size bytes of input, it will check
+ * if the whole buffer of the last subblock_data_size can be
+ * represented with repeats of chunks having size of rle bytes.
+ *
+ * If there are consecutive identical buffers of subblock_data_size
+ * bytes, they will be encoded using a single repeat entry if
+ * possible.
+ *
+ * If need arises, more advanced RLE can be implemented later
+ * without breaking API or ABI.
+ */
+ uint32_t rle;
+# define LZMA_SUBBLOCK_RLE_OFF 0
+# define LZMA_SUBBLOCK_RLE_MIN 1
+# define LZMA_SUBBLOCK_RLE_MAX 256
+
+ /**
+ * \brief Subfilter remote control
+ *
+ * When the Subblock filter is initialized, this variable must be
+ * LZMA_SUBFILTER_NONE or LZMA_SUBFILTER_SET.
+ *
+ * When subfilter_mode is LZMA_SUBFILTER_NONE, the application may
+ * put Subfilter options to subfilter_options structure, and then
+ * set subfilter_mode to LZMA_SUBFILTER_SET. This implies setting
+ * flush to true. No new input data will be read until the Subfilter
+ * has been enabled. Once the Subfilter has been enabled, liblzma
+ * will set subfilter_mode to LZMA_SUBFILTER_RUN.
+ *
+ * When subfilter_mode is LZMA_SUBFILTER_RUN, the application may
+ * set subfilter_mode to LZMA_SUBFILTER_FINISH. No new input data
+ * will be read until the Subfilter has been finished. Once the
+ * Subfilter has been finished, liblzma will set subfilter_mode
+ * to LZMA_SUBFILTER_NONE.
+ *
+ * If the intent is to have Subfilter enabled to the very end of
+ * the data, it is not needed to separately disable Subfilter with
+ * LZMA_SUBFILTER_FINISH. Using LZMA_FINISH as the second argument
+ * of lzma_code() will make the Subblock encoder to disable the
+ * Subfilter once all the data has been ran through the Subfilter.
+ *
+ * \note This variable is ignored if allow_subfilters is false.
+ */
+ lzma_subfilter_mode subfilter_mode;
+
+ /**
+ * \brief Subfilter and its options
+ *
+ * When no Subfilter is used, the data is copied as is into Subblocks.
+ * Setting a Subfilter allows encoding some parts of the data with
+ * an additional filter. It is possible to many different Subfilters
+ * in the same Block, although only one can be used at once.
+ *
+ * \note This variable is ignored if allow_subfilters is false.
+ */
+ lzma_options_filter subfilter_options;
+
+} lzma_options_subblock;
diff --git a/src/liblzma/api/lzma/version.h b/src/liblzma/api/lzma/version.h
new file mode 100644
index 00000000..ffbf8a81
--- /dev/null
+++ b/src/liblzma/api/lzma/version.h
@@ -0,0 +1,59 @@
+/**
+ * \file lzma/version.h
+ * \brief Version number
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Compile-time version number
+ *
+ * The version number is of format xyyyuuus where
+ * - x is the major LZMA SDK version
+ * - yyy is the minor LZMA SDK version
+ * - uuu is LZMA Utils version (reset to zero every time SDK version
+ * is incremented)
+ * - s indicates stability: 0 = alpha, 1 = beta, 2 = stable
+ */
+#define LZMA_VERSION UINT32_C(40420010)
+
+
+/**
+ * \brief liblzma version number as an integer
+ *
+ * This is the value of LZMA_VERSION macro at the compile time of liblzma.
+ * This allows the application to compare if it was built against the same,
+ * older, or newer version of liblzma that is currently running.
+ */
+extern const uint32_t lzma_version_number;
+
+
+/**
+ * \brief Returns versions number of liblzma as a string
+ *
+ * This function may be useful if you want to display which version of
+ * libilzma your application is currently using.
+ *
+ * \return Returns a pointer to a statically allocated string constant,
+ * which contains the version number of liblzma. The format of
+ * the version string is usually (but not necessarily) x.y.z
+ * e.g. "4.42.1". Alpha and beta versions contain a suffix
+ * ("4.42.0alpha").
+ */
+extern const char *const lzma_version_string;
diff --git a/src/liblzma/api/lzma/vli.h b/src/liblzma/api/lzma/vli.h
new file mode 100644
index 00000000..322014e1
--- /dev/null
+++ b/src/liblzma/api/lzma/vli.h
@@ -0,0 +1,244 @@
+/**
+ * \file lzma/vli.h
+ * \brief Variable-length integer handling
+ *
+ * \author Copyright (C) 1999-2006 Igor Pavlov
+ * \author Copyright (C) 2007 Lasse Collin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef LZMA_H_INTERNAL
+# error Never include this file directly. Use <lzma.h> instead.
+#endif
+
+
+/**
+ * \brief Maximum supported value of variable-length integer
+ */
+#define LZMA_VLI_VALUE_MAX (UINT64_MAX / 2)
+
+/**
+ * \brief VLI value to denote that the value is unknown
+ */
+#define LZMA_VLI_VALUE_UNKNOWN UINT64_MAX
+
+/**
+ * \brief Maximum supported length of variable length integers
+ */
+#define LZMA_VLI_BYTES_MAX 9
+
+
+/**
+ * \brief VLI constant suffix
+ */
+#define LZMA_VLI_C(n) UINT64_C(n)
+
+
+/**
+ * \brief Variable-length integer type
+ *
+ * This will always be unsigned integer. Valid VLI values are in the range
+ * [0, LZMA_VLI_VALUE_MAX]. Unknown value is indicated with
+ * LZMA_VLI_VALUE_UNKNOWN, which is the maximum value of the underlaying
+ * integer type (this feature is useful in several situations).
+ *
+ * In future, even if lzma_vli is typdefined to something else than uint64_t,
+ * it is guaranteed that 2 * LZMA_VLI_VALUE_MAX will not overflow lzma_vli.
+ * This simplifies integer overflow detection.
+ */
+typedef uint64_t lzma_vli;
+
+
+/**
+ * \brief Simple macro to validate variable-length integer
+ *
+ * This is useful to test that application has given acceptable values
+ * for example in the uncompressed_size and compressed_size variables.
+ *
+ * \return True if the integer is representable as VLI or if it
+ * indicates unknown value.
+ */
+#define lzma_vli_is_valid(vli) \
+ ((vli) <= LZMA_VLI_VALUE_MAX || (vli) == LZMA_VLI_VALUE_UNKNOWN)
+
+
+/**
+ * \brief Sets VLI to given value with error checking
+ *
+ * \param dest Target variable which must have type of lzma_vli.
+ * \param src New value to be stored to dest.
+ * \param limit Maximum allowed value for src.
+ *
+ * \return False on success, true on error. If an error occurred,
+ * dest is left in undefined state (i.e. it's possible that
+ * it will be different in newer liblzma versions).
+ */
+#define lzma_vli_set_lim(dest, src, limit) \
+ ((src) > (limit) || ((dest) = (src)) > (limit))
+
+/**
+ * \brief
+ */
+#define lzma_vli_add_lim(dest, src, limit) \
+ ((src) > (limit) || ((dest) += (src)) > (limit))
+
+#define lzma_vli_add2_lim(dest, src1, src2, limit) \
+ (lzma_vli_add_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit))
+
+#define lzma_vli_add3_lim(dest, src1, src2, src3, limit) \
+ (lzma_vli_add_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit) \
+ || lzma_vli_add_lim(dest, src3, limit))
+
+#define lzma_vli_add4_lim(dest, src1, src2, src3, src4, limit) \
+ (lzma_vli_add_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit) \
+ || lzma_vli_add_lim(dest, src3, limit) \
+ || lzma_vli_add_lim(dest, src4, limit))
+
+#define lzma_vli_sum_lim(dest, src1, src2, limit) \
+ (lzma_vli_set_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit))
+
+#define lzma_vli_sum3_lim(dest, src1, src2, src3, limit) \
+ (lzma_vli_set_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit) \
+ || lzma_vli_add_lim(dest, src3, limit))
+
+#define lzma_vli_sum4_lim(dest, src1, src2, src3, src4, limit) \
+ (lzma_vli_set_lim(dest, src1, limit) \
+ || lzma_vli_add_lim(dest, src2, limit) \
+ || lzma_vli_add_lim(dest, src3, limit) \
+ || lzma_vli_add_lim(dest, src4, limit))
+
+#define lzma_vli_set(dest, src) lzma_vli_set_lim(dest, src, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_add(dest, src) lzma_vli_add_lim(dest, src, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_add2(dest, src1, src2) \
+ lzma_vli_add2_lim(dest, src1, src2, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_add3(dest, src1, src2, src3) \
+ lzma_vli_add3_lim(dest, src1, src2, src3, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_add4(dest, src1, src2, src3, src4) \
+ lzma_vli_add4_lim(dest, src1, src2, src3, src4, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_sum(dest, src1, src2) \
+ lzma_vli_sum_lim(dest, src1, src2, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_sum3(dest, src1, src2, src3) \
+ lzma_vli_sum3_lim(dest, src1, src2, src3, LZMA_VLI_VALUE_MAX)
+
+#define lzma_vli_sum4(dest, src1, src2, src3, src4) \
+ lzma_vli_sum4_lim(dest, src1, src2, src3, src4, LZMA_VLI_VALUE_MAX)
+
+
+/**
+ * \brief Encodes variable-length integer
+ *
+ * In the new .lzma format, most integers are encoded in variable-length
+ * representation. This saves space when smaller values are more likely
+ * than bigger values.
+ *
+ * The encoding scheme encodes seven bits to every byte, using minimum
+ * number of bytes required to represent the given value. In other words,
+ * it puts 7-63 bits into 1-9 bytes. This implementation limits the number
+ * of bits used to 63, thus num must be at maximum of INT64_MAX / 2. You
+ * may use LZMA_VLI_VALUE_MAX for clarity.
+ *
+ * \param vli Integer to be encoded
+ * \param vli_pos How many bytes have already been written out. This
+ * must be less than 9 before calling this function.
+ * \param vli_size Minimum size that the variable-length representation
+ * must take. This is useful if you want to use
+ * variable-length integers as padding. Usually you want
+ * to set this to zero. The maximum allowed value is 9.
+ * \param out Beginning of the output buffer
+ * \param out_pos The next byte will be written to out[*out_pos].
+ * \param out_size Size of the out buffer; the first byte into
+ * which no data is written to is out[out_size].
+ *
+ * \return - LZMA_OK: So far all OK, but the integer is not
+ * completely written out yet.
+ * - LZMA_STREAM_END: Integer successfully encoded.
+ * - LZMA_BUF_ERROR: No output space (*out_pos == out_size)
+ * - LZMA_PROG_ERROR: Arguments are not sane.
+ */
+extern lzma_ret lzma_vli_encode(
+ lzma_vli vli, size_t *lzma_restrict vli_pos, size_t vli_size,
+ uint8_t *lzma_restrict out, size_t *lzma_restrict out_pos,
+ size_t out_size);
+
+
+/**
+ * \brief Decodes variable-length integer
+ *
+ * \param vli Pointer to decoded integer. The decoder will
+ * initialize it to zero when *vli_pos == 0, so
+ * application isn't required to initialize *vli.
+ * \param vli_pos How many bytes have already been decoded. When
+ * starting to decode a new integer, *vli_pos must
+ * be initialized to zero.
+ * \param in Beginning of the input buffer
+ * \param in_pos The next byte will be read from in[*in_pos].
+ * \param in_size Size of the input buffer; the first byte that
+ * won't be read is in[in_size].
+ *
+ * \return - LZMA_OK: So far all OK, but the integer is not
+ * completely decoded yet.
+ * - LZMA_STREAM_END: Integer successfully decoded.
+ * - LZMA_BUF_ERROR: No input data (*in_pos == in_size)
+ * - LZMA_DATA_ERROR: Integer is longer than nine bytes.
+ * - LZMA_PROG_ERROR: Arguments are not sane.
+ */
+extern lzma_ret lzma_vli_decode(lzma_vli *lzma_restrict vli,
+ size_t *lzma_restrict vli_pos, const uint8_t *lzma_restrict in,
+ size_t *lzma_restrict in_pos, size_t in_size);
+
+
+/**
+ * \brief Decodes variable-length integer reading buffer backwards
+ *
+ * The variable-length integer encoding is designed so that it can be read
+ * either from the beginning to the end, or from the end to the beginning.
+ * This feature is needed to make the Stream parseable backwards;
+ * specifically, to read the Backward Size field in Stream Footer.
+ *
+ * \param vli Pointer to variable to hold the decoded integer.
+ * \param in Beginning of the input buffer
+ * \param in_size Number of bytes available in the in[] buffer.
+ * On successful decoding, this is updated to match
+ * the number of bytes used. (in[*in_size - 1] is the
+ * first byte to process. After successful decoding,
+ * in[*in_size] will point to the first byte of the
+ * variable-length integer.)
+ *
+ * \return - LZMA_OK: Decoding successful
+ * - LZMA_DATA_ERROR: No valid variable-length integer was found.
+ * - LZMA_BUF_ERROR: Not enough input. Note that in practice,
+ * this tends to be a sign of broken input, because the
+ * applications usually do give as much input to this function
+ * as the applications have available.
+ */
+extern lzma_ret lzma_vli_reverse_decode(
+ lzma_vli *vli, const uint8_t *in, size_t *in_size);
+
+
+/**
+ * \brief Gets the minimum number of bytes required to encode vli
+ *
+ * \return Number of bytes on success (1-9). If vli isn't valid,
+ * zero is returned.
+ */
+extern size_t lzma_vli_size(lzma_vli vli);