aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api/lzma
diff options
context:
space:
mode:
Diffstat (limited to 'src/liblzma/api/lzma')
-rw-r--r--src/liblzma/api/lzma/alone.h32
-rw-r--r--src/liblzma/api/lzma/auto.h7
-rw-r--r--src/liblzma/api/lzma/base.h15
-rw-r--r--src/liblzma/api/lzma/block.h306
-rw-r--r--src/liblzma/api/lzma/check.h18
-rw-r--r--src/liblzma/api/lzma/copy.h29
-rw-r--r--src/liblzma/api/lzma/easy.h61
-rw-r--r--src/liblzma/api/lzma/extra.h114
-rw-r--r--src/liblzma/api/lzma/filter.h5
-rw-r--r--src/liblzma/api/lzma/index.h204
-rw-r--r--src/liblzma/api/lzma/index_hash.h94
-rw-r--r--src/liblzma/api/lzma/info.h315
-rw-r--r--src/liblzma/api/lzma/lzma.h2
-rw-r--r--src/liblzma/api/lzma/metadata.h100
-rw-r--r--src/liblzma/api/lzma/raw.h20
-rw-r--r--src/liblzma/api/lzma/stream.h157
-rw-r--r--src/liblzma/api/lzma/stream_flags.h146
-rw-r--r--src/liblzma/api/lzma/version.h2
-rw-r--r--src/liblzma/api/lzma/vli.h83
19 files changed, 522 insertions, 1188 deletions
diff --git a/src/liblzma/api/lzma/alone.h b/src/liblzma/api/lzma/alone.h
index 1a6b8e27..72299773 100644
--- a/src/liblzma/api/lzma/alone.h
+++ b/src/liblzma/api/lzma/alone.h
@@ -22,36 +22,6 @@
/**
- * \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.
@@ -68,7 +38,7 @@ typedef struct {
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_alone_encoder(
- lzma_stream *strm, const lzma_options_alone *options);
+ lzma_stream *strm, const lzma_options_lzma *options);
/**
diff --git a/src/liblzma/api/lzma/auto.h b/src/liblzma/api/lzma/auto.h
index 327e726f..fd5bf7d2 100644
--- a/src/liblzma/api/lzma/auto.h
+++ b/src/liblzma/api/lzma/auto.h
@@ -29,13 +29,8 @@
* 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);
+extern lzma_ret lzma_auto_decoder(lzma_stream *strm);
diff --git a/src/liblzma/api/lzma/base.h b/src/liblzma/api/lzma/base.h
index d39bfe95..b0dfed95 100644
--- a/src/liblzma/api/lzma/base.h
+++ b/src/liblzma/api/lzma/base.h
@@ -128,6 +128,21 @@ typedef enum {
* In the decoder, this is only a warning and decoding can
* still proceed normally (but the Check is ignored).
*/
+
+ LZMA_FORMAT_ERROR = -8,
+ /**<
+ * \brief Unknown file format
+ */
+
+ LZMA_MEMLIMIT_ERROR = -9
+ /**
+ * \brief Memory usage limit was reached
+ *
+ * Decoder would need more memory than allowed by the
+ * specified memory usage limit. To continue decoding,
+ * the memory usage limit has to be increased. See functions
+ * lzma_memlimit_get() and lzma_memlimit_set().
+ */
} lzma_ret;
diff --git a/src/liblzma/api/lzma/block.h b/src/liblzma/api/lzma/block.h
index 210c1d87..a8941165 100644
--- a/src/liblzma/api/lzma/block.h
+++ b/src/liblzma/api/lzma/block.h
@@ -33,95 +33,31 @@
*/
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.
+ * \brief Size of the Block Header
*
* 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_block_header_size()
+ * - lzma_block_header_decode()
*/
- lzma_bool has_backward_size;
+ uint32_t header_size;
+# define LZMA_BLOCK_HEADER_SIZE_MIN 8
+# define LZMA_BLOCK_HEADER_SIZE_MAX 1024
/**
- * \brief True if Block coder should take care of Padding
+ * \brief Type of integrity Check
*
- * 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.
+ * 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_bool handle_padding;
+ lzma_check_type check;
/**
* \brief Size of the Compressed Data in bytes
@@ -134,12 +70,12 @@ typedef struct {
*
* Read by:
* - lzma_block_header_size()
- * - lzma_block_header_encoder()
+ * - lzma_block_header_encode()
* - lzma_block_encoder()
* - lzma_block_decoder()
*
* Written by:
- * - lzma_block_header_decoder()
+ * - lzma_block_header_decode()
* - lzma_block_encoder()
* - lzma_block_decoder()
*/
@@ -163,167 +99,61 @@ typedef struct {
*
* Read by:
* - lzma_block_header_size()
- * - lzma_block_header_encoder()
+ * - lzma_block_header_encode()
* - lzma_block_encoder()
* - lzma_block_decoder()
*
* Written by:
- * - lzma_block_header_decoder()
+ * - lzma_block_header_decode()
* - 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.
+ * There can be 1-4 filters. The end of the array is marked with
+ * .id = LZMA_VLI_VALUE_UNKNOWN.
*
* Read by:
* - lzma_block_header_size()
- * - lzma_block_header_encoder()
+ * - lzma_block_header_encode()
* - 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()
+ * - lzma_block_header_decode(): Note that this does NOT free()
+ * the old filter options structures. All unused filters[] will
+ * have .id == LZMA_VLI_VALUE_UNKNOWN and .options == NULL. If
+ * decoding fails, all filters[] are guaranteed to be
+ * LZMA_VLI_VALUE_UNKNOWN and NULL.
+ *
+ * \note Because of the array is terminated with
+ * .id = LZMA_VLI_VALUE_UNKNOWN, the actual array must
+ * have LZMA_BLOCK_FILTERS_MAX + 1 members or the Block
+ * Header decoder will overflow the buffer.
*/
- int32_t padding;
-# define LZMA_BLOCK_HEADER_PADDING_AUTO (-1)
-# define LZMA_BLOCK_HEADER_PADDING_MIN 0
-# define LZMA_BLOCK_HEADER_PADDING_MAX 31
+ lzma_options_filter *filters;
+# define LZMA_BLOCK_FILTERS_MAX 4
- /**
- * \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;
+} lzma_options_block;
- /**
- * \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 Decodes the Block Header Size field
+ *
+ * To decode Block Header using lzma_block_header_decode(), the size of the
+ * Block Header has to be known and stored into lzma_options_block.header_size.
+ * The size can be calculated from the first byte of a Block using this macro.
+ * Note that if the first byte is 0x00, it indicates beginning of Index; use
+ * this macro only when the byte is not 0x00.
+ */
+#define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
/**
- * \brief Calculates the size of Header Padding and Block Header
+ * \brief Calculates the size of Block Header
*
* \return - LZMA_OK: Size calculated successfully and stored to
* options->header_size.
@@ -353,24 +183,62 @@ extern lzma_ret lzma_block_header_size(lzma_options_block *options);
* - LZMA_PROG_ERROR
*/
extern lzma_ret lzma_block_header_encode(
- uint8_t *out, const lzma_options_block *options);
+ const lzma_options_block *options, uint8_t *out);
/**
- * \brief Initializes Block Header decoder
+ * \brief Decodes Block Header
*
- * Because the results of this decoder are placed into *options,
- * strm->next_in, strm->avail_in, and strm->total_in are not used.
+ * Decoding of the Block options is done with a single call instead of
+ * first initializing and then doing the actual work with lzma_code().
*
- * The only valid `action' with lzma_code() is LZMA_RUN.
+ * \param options Destination for block options
+ * \param allocator lzma_allocator for custom allocator functions.
+ * Set to NULL to use malloc().
+ * \param in Beginning of the input buffer. This must be
+ * at least options->header_size bytes.
*
- * \return - LZMA_OK: Encoding was successful. options->header_size
+ * \return - LZMA_OK: Decoding 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);
+extern lzma_ret lzma_block_header_decode(lzma_options_block *options,
+ lzma_allocator *allocator, const uint8_t *in);
+
+
+/**
+ * \brief Sets Compressed Size according to Total Size
+ *
+ * Block Header stores Compressed Size, but Index has Total Size. If the
+ * application has already parsed the Index and is now decoding Blocks,
+ * it can calculate Compressed Size from Total Size. This function does
+ * exactly that with error checking, so application doesn't need to check,
+ * for example, if the value in Index is too small to contain even the
+ * Block Header. Note that you need to call this function after decoding
+ * the Block Header field.
+ *
+ * \return - LZMA_OK: options->compressed_size was set successfully.
+ * - LZMA_DATA_ERROR: total_size is too small compared to
+ * options->header_size and lzma_check_sizes[options->check].
+ * - LZMA_PROG_ERROR: Some values are invalid. For example,
+ * total_size and options->header_size must be multiples
+ * of four, total_size must be at least 12, and
+ * options->header_size between 8 and 1024 inclusive.
+ */
+extern lzma_ret lzma_block_total_size_set(
+ lzma_options_block *options, lzma_vli total_size);
+
+
+/**
+ * \brief Calculates Total Size
+ *
+ * This function can be useful after decoding a Block to get Total Size
+ * that is stored in Index.
+ *
+ * \return Total Size on success, or zero on error.
+ */
+extern lzma_vli lzma_block_total_size_get(const lzma_options_block *options);
/**
diff --git a/src/liblzma/api/lzma/check.h b/src/liblzma/api/lzma/check.h
index 4a2a453b..dcba8269 100644
--- a/src/liblzma/api/lzma/check.h
+++ b/src/liblzma/api/lzma/check.h
@@ -43,14 +43,14 @@ typedef enum {
* Size of the Check field: 4 bytes
*/
- LZMA_CHECK_CRC64 = 3,
+ LZMA_CHECK_CRC64 = 4,
/**<
* CRC64 using the polynomial from the ECMA-182 standard
*
* Size of the Check field: 8 bytes
*/
- LZMA_CHECK_SHA256 = 5
+ LZMA_CHECK_SHA256 = 10
/**<
* SHA-256
*
@@ -62,7 +62,7 @@ typedef enum {
/**
* \brief Maximum valid Check ID
*
- * The .lzma file format specification specifies eight Check IDs (0-7). Some
+ * The .lzma file format specification specifies eight Check IDs (0-15). 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,
@@ -70,7 +70,7 @@ typedef enum {
*
* FIXME bad desc
*/
-#define LZMA_CHECK_ID_MAX 7
+#define LZMA_CHECK_ID_MAX 15
/**
@@ -89,13 +89,19 @@ extern const lzma_bool lzma_available_checks[LZMA_CHECK_ID_MAX + 1];
* 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 }
+ * section 2.1.1.2 of the .lzma file format specification:
+ * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
*/
extern const uint32_t lzma_check_sizes[LZMA_CHECK_ID_MAX + 1];
/**
+ * \brief Maximum size of a Check field
+ */
+#define LZMA_CHECK_SIZE_MAX 64
+
+
+/**
* \brief Calculate CRC32
*
* Calculates CRC32 using the polynomial from the IEEE 802.3 standard.
diff --git a/src/liblzma/api/lzma/copy.h b/src/liblzma/api/lzma/copy.h
deleted file mode 100644
index f5617462..00000000
--- a/src/liblzma/api/lzma/copy.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * \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/easy.h b/src/liblzma/api/lzma/easy.h
index b04c7b4f..d83a79a2 100644
--- a/src/liblzma/api/lzma/easy.h
+++ b/src/liblzma/api/lzma/easy.h
@@ -69,7 +69,7 @@ typedef enum {
/**
- * \brief Default compression level for Data Blocks
+ * \brief Default compression level
*
* Data Blocks contain the actual compressed data. It's not straightforward
* to recommend a default level, because in some cases keeping the resource
@@ -80,16 +80,6 @@ typedef enum {
/**
- * \brief Default compression level for Metadata Blocks
- *
- * Metadata Blocks are present only in Multi-Block Streams. Metadata Blocks
- * contain the Extra Records (if any) and some book-keeping data that is
- * used by decoders.
- */
-#define LZMA_EASY_METADATA_DEFAULT LZMA_EASY_LZMA_3
-
-
-/**
* \brief Calculates rough memory requirements of a compression level
*
* This function is a wrapper for lzma_memory_usage(), which is declared
@@ -104,11 +94,11 @@ extern uint32_t lzma_easy_memory_usage(lzma_easy_level level);
/**
- * \brief Initializes Single-Block .lzma Stream encoder
+ * \brief Initializes .lzma Stream encoder
*
* This function is intended for those who just want to use the basic LZMA
* features (that is, most developers out there). Lots of assumptions are
- * made, which are correct for most situations or at least good enough.
+ * made, which are correct or at least good enough for most situations.
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
@@ -125,50 +115,7 @@ extern uint32_t lzma_easy_memory_usage(lzma_easy_level level);
*
* If initialization succeeds, use lzma_code() to do the actual encoding.
* Valid values for `action' (the second argument of lzma_code()) are
- * LZMA_RUN, LZMA_SYNC_FLUSH, and LZMA_FINISH. In future, there may be
- * compression levels that don't support LZMA_SYNC_FLUSH.
- */
-extern lzma_ret lzma_easy_encoder_single(
- lzma_stream *strm, lzma_easy_level level);
-
-
-/**
- * \brief Initializes Multi-Block .lzma Stream encoder
- *
- * If you want to be able to store Extra Records or want to be able to use
- * LZMA_FULL_FLUSH, you need to create a Multi-Block Stream.
- *
- * \param strm Pointer to lzma_stream that is at least initialized
- * with LZMA_STREAM_INIT.
- * \param level Compression level to use for the data being encoded.
- * \param metadata_level
- * Compression level to use for Metadata Blocks.
- * Metadata Blocks contain the Extra Records (if any)
- * and some book-keeping data that is used by decoders.
- * \param header Pointer to a list of Extra Records to be stored to
- * the Header Metadata Block. Set this to NULL to omit
- * Header Metadata Block completely. The list must be
- * kept available until the encoding has finished.
- * \param footer Pointer to a list of Extra Records to be stored to
- * the Footer Metadata Block. Set this to NULL if you
- * don't want to store any Extra Records (the Footer
- * Metadata Block will still be written for other
- * reasons.) The list must be kept available until
- * the encoding has finished.
- *
- * \return - LZMA_OK: Initialization succeeded. Use lzma_code() to
- * encode your data.
- * - LZMA_MEM_ERROR: Memory allocation failed. All memory
- * previously allocated for *strm is now freed.
- * - LZMA_HEADER_ERROR: The given compression level is not
- * supported by this build of liblzma.
- *
- * If initialization succeeds, use lzma_code() to do the actual encoding.
- * Valid values for `action' (the second argument of lzma_code()) are
* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
* there may be compression levels that don't support LZMA_SYNC_FLUSH.
- * LZMA_FULL_FLUSH will always work with all compression levels.
*/
-extern lzma_ret lzma_easy_encoder_multi(lzma_stream *strm,
- lzma_easy_level level, lzma_easy_level metadata_level,
- const lzma_extra *header, const lzma_extra *footer);
+extern lzma_ret lzma_easy_encoder(lzma_stream *strm, lzma_easy_level level);
diff --git a/src/liblzma/api/lzma/extra.h b/src/liblzma/api/lzma/extra.h
deleted file mode 100644
index 29426a74..00000000
--- a/src/liblzma/api/lzma/extra.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * \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
index a8bdd4bd..412c30e5 100644
--- a/src/liblzma/api/lzma/filter.h
+++ b/src/liblzma/api/lzma/filter.h
@@ -162,5 +162,6 @@ extern lzma_ret lzma_filter_flags_encode(uint8_t *out, size_t *out_pos,
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
-extern lzma_ret lzma_filter_flags_decoder(
- lzma_stream *strm, lzma_options_filter *options);
+extern lzma_ret lzma_filter_flags_decode(
+ lzma_options_filter *options, lzma_allocator *allocator,
+ const uint8_t *in, size_t *in_pos, size_t in_size);
diff --git a/src/liblzma/api/lzma/index.h b/src/liblzma/api/lzma/index.h
index 7e59c4b3..13cddf47 100644
--- a/src/liblzma/api/lzma/index.h
+++ b/src/liblzma/api/lzma/index.h
@@ -22,63 +22,211 @@
/**
- * \brief
- *
- * FIXME desc
+ * \brief Opaque data type to hold the Index
*/
typedef struct lzma_index_s lzma_index;
-struct lzma_index_s {
+
+
+/**
+ * \brief Index Record and its location
+ */
+typedef struct {
/**
- * \brief Total Size of the Block
- *
- * This includes Block Header, Compressed Data, and Block Footer.
+ * Total Size of a Block.
*/
lzma_vli total_size;
/**
- * \brief Uncompressed Size of the Block
+ * Uncompressed Size of a Block
*/
lzma_vli uncompressed_size;
/**
- * \brief Pointer to the next Index Record
- *
- * This is NULL on the last Index Record.
+ * Offset of the first byte of a Block relative to the beginning
+ * of the Stream, or if there are multiple Indexes combined,
+ * relative to the beginning of the first Stream.
*/
- lzma_index *next;
-};
+ lzma_vli stream_offset;
+
+ /**
+ * Uncompressed offset
+ */
+ lzma_vli uncompressed_offset;
+
+} lzma_index_record;
/**
- * \brief Duplicates an Index list
+ * \brief Allocate and initialize a new lzma_index structure
+ *
+ * If i is NULL, a new lzma_index structure is allocated, initialized,
+ * and a pointer to it returned. If allocation fails, NULL is returned.
*
- * \return A copy of the Index list, or NULL if memory allocation
- * failed or the original Index was empty.
+ * If i 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 i given as argument.
*/
-extern lzma_index *lzma_index_dup(
- const lzma_index *index, lzma_allocator *allocator);
+extern lzma_index *lzma_index_init(lzma_index *i, lzma_allocator *allocator);
+
+
+/**
+ * \brief Deallocate the Index
+ */
+extern void lzma_index_end(lzma_index *i, lzma_allocator *allocator);
/**
- * \brief Frees an Index list
+ * \brief Add a new Record to an Index
*
- * All Index Recors in the list are freed. This function is convenient when
- * getting rid of lzma_metadata structures containing an Index.
+ * \param index Pointer to a lzma_index structure
+ * \param total_size Total Size of a Block
+ * \param uncompressed_size Uncompressed Size of a Block, or
+ * LZMA_VLI_VALUE_UNKNOWN to indicate padding.
+ *
+ * Appending a new Record does not affect the read position.
+ *
+ * \return - LZMA_OK
+ * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
+ * Stream or size of the Index field would grow too big.
+ * - LZMA_PROG_ERROR
*/
-extern void lzma_index_free(lzma_index *index, lzma_allocator *allocator);
+extern lzma_ret lzma_index_append(lzma_index *i, lzma_allocator *allocator,
+ lzma_vli total_size, lzma_vli uncompressed_size);
/**
- * \brief Calculates information about the Index
+ * \brief Get the number of Records
+ */
+extern lzma_vli lzma_index_count(const lzma_index *i);
+
+
+/**
+ * \brief Get the size of the Index field as bytes
+ *
+ * This is needed to verify the Index Size field from the Stream Footer.
+ */
+extern lzma_vli lzma_index_size(const lzma_index *i);
+
+
+/**
+ * \brief Get the total size of the Blocks
+ *
+ * This doesn't include the Stream Header, Stream Footer, Stream Padding,
+ * or Index fields.
+ */
+extern lzma_vli lzma_index_total_size(const lzma_index *i);
+
+
+/**
+ * \brief Get the total size of the Stream
+ *
+ * If multiple Indexes have been combined, this works as if the Blocks
+ * were in a single Stream.
+ */
+extern lzma_vli lzma_index_stream_size(const lzma_index *i);
+
+
+/**
+ * \brief Get the total size of the file
*
- * \return LZMA_OK on success, LZMA_PROG_ERROR on error. FIXME
+ * When no Indexes have been combined with lzma_index_cat(), this function is
+ * identical to lzma_index_stream_size(). If multiple Indexes have been
+ * combined, this includes also the possible Stream Padding fields.
+ */
+extern lzma_vli lzma_index_file_size(const lzma_index *i);
+
+
+/**
+ * \brief Get the uncompressed size of the Stream
*/
-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);
+extern lzma_vli lzma_index_uncompressed_size(const lzma_index *i);
+
+
+/**
+ * \brief Get the next Record from the Index
+ */
+extern lzma_bool lzma_index_read(lzma_index *i, lzma_index_record *record);
+
+
+/**
+ * \brief Rewind the Index
+ *
+ * Rewind the Index so that next call to lzma_index_read() will return the
+ * first Record.
+ */
+extern void lzma_index_rewind(lzma_index *i);
+
+
+/**
+ * \brief Locate a Record
+ *
+ * When the Index is available, it is possible to do random-access reading
+ * with granularity of Block size.
+ *
+ * \param i Pointer to lzma_index structure
+ * \param record Pointer to a structure to hold the search results
+ * \param target Uncompressed target offset
+ *
+ * If the target is smaller than the uncompressed size of the Stream (can be
+ * checked with lzma_index_uncompressed_size()):
+ * - Information about the Record containing the requested uncompressed
+ * offset is stored into *record.
+ * - Read offset will be adjusted so that calling lzma_index_read() can be
+ * used to read subsequent Records.
+ * - This function returns false.
+ *
+ * If target is greater than the uncompressed size of the Stream, *record
+ * and the read position are not modified, and this function returns true.
+ */
+extern lzma_bool lzma_index_locate(
+ lzma_index *i, lzma_index_record *record, lzma_vli target);
+
+
+/**
+ * \brief Concatenate Indexes of two Streams
+ *
+ *
+ *
+ * \param dest Destination Index after which src is appended Source
+ * \param src Index. The memory allocated for this is either moved
+ * to be part of *dest or freed iff the function call
+ * succeeds, and src will be an invalid pointer.
+ * \param allocator Custom memory allocator; can be NULL to use
+ * malloc() and free().
+ * \param padding Size of the Stream Padding field between Streams.
+ *
+ * \return - LZMA_OK: Indexes concatenated successfully.
+ * - LZMA_DATA_ERROR: *dest would grow too big.
+ * - LZMA_MEM_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern lzma_ret lzma_index_cat(lzma_index *lzma_restrict dest,
+ lzma_index *lzma_restrict src,
+ lzma_allocator *allocator, lzma_vli padding);
+
+
+/**
+ * \brief Duplicates an Index list
+ *
+ * \return A copy of the Index, or NULL if memory allocation failed.
+ */
+extern lzma_index *lzma_index_dup(
+ const lzma_index *i, lzma_allocator *allocator);
/**
* \brief Compares if two Index lists are identical
*/
-extern lzma_bool lzma_index_is_equal(const lzma_index *a, const lzma_index *b);
+extern lzma_bool lzma_index_equal(const lzma_index *a, const lzma_index *b);
+
+
+/**
+ * \brief Initializes Index encoder
+ */
+extern lzma_ret lzma_index_encoder(lzma_stream *strm, lzma_index *i);
+
+
+/**
+ * \brief Initializes Index decoder
+ */
+extern lzma_ret lzma_index_decoder(lzma_stream *strm, lzma_index **i);
diff --git a/src/liblzma/api/lzma/index_hash.h b/src/liblzma/api/lzma/index_hash.h
new file mode 100644
index 00000000..1edbbeaa
--- /dev/null
+++ b/src/liblzma/api/lzma/index_hash.h
@@ -0,0 +1,94 @@
+/**
+ * \file lzma/index_hash.h
+ * \brief Validates Index by using a hash function
+ *
+ * Instead of constructing complete Index while decoding Blocks, Index hash
+ * calculates a hash of the Block sizes and Index, and then compares the
+ * hashes. This way memory usage is constant even with large number of
+ * Blocks and huge Index.
+ *
+ * \author Copyright (C) 2008 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 to hold the Index hash
+ */
+typedef struct lzma_index_hash_s lzma_index_hash;
+
+
+/**
+ * \brief Allocate and initialize a new lzma_index_hash structure
+ *
+ * If index_hash is NULL, a new lzma_index_hash structure is allocated,
+ * initialized, and a pointer to it returned. If allocation fails, NULL
+ * is returned.
+ *
+ * If index_hash 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 index_hash given as argument.
+ */
+extern lzma_index_hash *lzma_index_hash_init(
+ lzma_index_hash *index_hash, lzma_allocator *allocator);
+
+
+/**
+ * \brief Deallocate the Index hash
+ */
+extern void lzma_index_hash_end(
+ lzma_index_hash *index_hash, lzma_allocator *allocator);
+
+
+/**
+ * \brief Add a new Record to an Index hash
+ *
+ * \param index Pointer to a lzma_index_hash structure
+ * \param total_size Total Size of a Block
+ * \param uncompressed_size Uncompressed Size of a Block
+ *
+ * \return - LZMA_OK
+ * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
+ * Stream or size of the Index field would grow too big.
+ * - LZMA_PROG_ERROR: Invalid arguments or this function is being
+ * used when lzma_index_hash_decode() has already been used.
+ */
+extern lzma_ret lzma_index_hash_append(lzma_index_hash *index_hash,
+ lzma_vli total_size, lzma_vli uncompressed_size);
+
+
+/**
+ * \brief Decode the Index field
+ *
+ * \return - LZMA_OK: So far good, but more input is needed.
+ * - LZMA_STREAM_END: Index decoded successfully and it matches
+ * the Records given with lzma_index_hash_append().
+ * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
+ * information given with lzma_index_hash_append().
+ * - LZMA_PROG_ERROR
+ *
+ * \note Once decoding of the Index field has been started, no more
+ * Records can be added using lzma_index_hash_append().
+ */
+extern lzma_ret lzma_index_hash_decode(lzma_index_hash *index_hash,
+ const uint8_t *in, size_t *in_pos, size_t in_size);
+
+
+/**
+ * \brief Get the size of the Index field as bytes
+ *
+ * This is needed to verify the Index Size field from the Stream Footer.
+ */
+extern lzma_vli lzma_index_hash_size(const lzma_index_hash *index_hash);
diff --git a/src/liblzma/api/lzma/info.h b/src/liblzma/api/lzma/info.h
deleted file mode 100644
index 3a91850f..00000000
--- a/src/liblzma/api/lzma/info.h
+++ /dev/null
@@ -1,315 +0,0 @@
-/**
- * \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/lzma.h b/src/liblzma/api/lzma/lzma.h
index 9ff25d86..da0bb52d 100644
--- a/src/liblzma/api/lzma/lzma.h
+++ b/src/liblzma/api/lzma/lzma.h
@@ -152,7 +152,7 @@ typedef struct {
* because it uses the target buffer as the dictionary.
*/
uint32_t dictionary_size;
-# define LZMA_DICTIONARY_SIZE_MIN 1
+# define LZMA_DICTIONARY_SIZE_MIN (UINT32_C(1) << 12)
# define LZMA_DICTIONARY_SIZE_MAX (UINT32_C(1) << 30)
# define LZMA_DICTIONARY_SIZE_DEFAULT (UINT32_C(1) << 23)
diff --git a/src/liblzma/api/lzma/metadata.h b/src/liblzma/api/lzma/metadata.h
deleted file mode 100644
index 69592a3a..00000000
--- a/src/liblzma/api/lzma/metadata.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * \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
index c1ee41d8..db8cba15 100644
--- a/src/liblzma/api/lzma/raw.h
+++ b/src/liblzma/api/lzma/raw.h
@@ -30,20 +30,10 @@
* \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.
+ * number of filters is one and the maximum is four.
*
* The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
- * filter chain support it), or LZMA_FINISH.
+ * filter chain supports it), or LZMA_FINISH.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
@@ -51,8 +41,7 @@
* - 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);
+ lzma_stream *strm, const lzma_options_filter *options);
/**
@@ -68,5 +57,4 @@ extern lzma_ret lzma_raw_encoder(
* - 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);
+ lzma_stream *strm, const lzma_options_filter *options);
diff --git a/src/liblzma/api/lzma/stream.h b/src/liblzma/api/lzma/stream.h
index 346bdd17..4bb17e7d 100644
--- a/src/liblzma/api/lzma/stream.h
+++ b/src/liblzma/api/lzma/stream.h
@@ -22,157 +22,32 @@
/**
- * \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
- */
- const 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.
- */
- const 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.
+ * \brief Initializes .lzma Stream encoder
*
- * \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
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param filters Array of filters. This must be terminated with
+ * filters[n].id = LZMA_VLI_VALUE_UNKNOWN. There must
+ * be 1-4 filters, but there are restrictions on how
+ * multiple filters can be combined. FIXME Tell where
+ * to find more information.
+ * \param check Type of the integrity check to calculate from
+ * uncompressed data.
*
+ * \return - LZMA_OK: Initialization was successful.
+ * - LZMA_MEM_ERROR
+ * - LZMA_HEADER_ERROR
+ * - LZMA_PROG_ERROR
*/
-extern lzma_ret lzma_stream_encoder_multi(
- lzma_stream *strm, const lzma_options_stream *options);
+extern lzma_ret lzma_stream_encoder(lzma_stream *strm,
+ const lzma_options_filter *filters, lzma_check_type check);
/**
* \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_limiter, the Extra Records will be
- * allocated with it, and thus remain in the lzma_memory_limiter
- * 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);
+extern lzma_ret lzma_stream_decoder(lzma_stream *strm);
diff --git a/src/liblzma/api/lzma/stream_flags.h b/src/liblzma/api/lzma/stream_flags.h
index 070c91c9..f4c5c335 100644
--- a/src/liblzma/api/lzma/stream_flags.h
+++ b/src/liblzma/api/lzma/stream_flags.h
@@ -1,6 +1,6 @@
/**
* \file lzma/stream_flags.h
- * \brief .lzma Stream Header and Stream tail encoder and decoder
+ * \brief .lzma Stream Header and Stream Footer encoder and decoder
*
* \author Copyright (C) 1999-2006 Igor Pavlov
* \author Copyright (C) 2007 Lasse Collin
@@ -22,121 +22,113 @@
/**
- * \brief Size of Stream Header
+ * \brief Size of Stream Header and Stream Footer
*
- * Magic Bytes (6) + Stream Flags (1) + CRC32 (4)
+ * Stream Header and Stream Footer have the same size and they are not
+ * going to change even if a newer version of the .lzma file format is
+ * developed in future.
*/
-#define LZMA_STREAM_HEADER_SIZE (6 + 1 + 4)
+#define LZMA_STREAM_HEADER_SIZE 12
/**
- * \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
+ * Options for encoding and decoding Stream Header and Stream Footer
*/
typedef struct {
/**
- * Type of the Check calculated from uncompressed data
+ * Backward Size must be a multiple of four bytes. In this Stream
+ * format version Backward Size is the size of the Index field.
*/
- lzma_check_type check;
+ lzma_vli backward_size;
+# define LZMA_BACKWARD_SIZE_MIN 4
+# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
/**
- * 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.
+ * Type of the Check calculated from uncompressed data
*/
- lzma_bool is_multi;
+ lzma_check_type check;
} 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().
+ * \brief Encode Stream Header
*
- * \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 out Beginning of the output buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
* \param options Stream Header options to be encoded.
+ * options->index_size is ignored and doesn't
+ * need to be initialized.
*
* \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);
+ const lzma_stream_flags *options, uint8_t *out);
/**
- * \brief Encodes Stream tail
+ * \brief Encode Stream Footer
*
- * \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.
+ * \param out Beginning of the output buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ * \param options Stream Footer 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.
+ * \return - LZMA_OK: Encoding was successful.
+ * - LZMA_PROG_ERROR: Invalid options.
*/
-extern lzma_ret lzma_stream_tail_encode(
- uint8_t *out, const lzma_stream_flags *options);
+extern lzma_ret lzma_stream_footer_encode(
+ const lzma_stream_flags *options, uint8_t *out);
/**
- * \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
+ * \brief Decode Stream Header
*
- * The actual decoding is done with lzma_code() and freed with lzma_end().
+ * \param options Stream Header options to be encoded.
+ * \param in Beginning of the input buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * options->index_size is always set to LZMA_VLI_VALUE_UNKNOWN. This is to
+ * help comparing Stream Flags from Stream Header and Stream Footer with
+ * lzma_stream_flags_equal().
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
+ * buffer cannot be Stream Header.
+ * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
+ * is corrupt.
+ * - LZMA_HEADER_ERROR: Unsupported options are present
+ * in the header.
*/
-extern lzma_ret lzma_stream_header_decoder(
- lzma_stream *strm, lzma_stream_flags *options);
+extern lzma_ret lzma_stream_header_decode(
+ lzma_stream_flags *options, const uint8_t *in);
/**
- * \brief Initializes Stream tail decoder
+ * \brief Decode Stream Footer
*
- * \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.
+ * \param options Stream Header options to be encoded.
+ * \param in Beginning of the input buffer of
+ * LZMA_STREAM_HEADER_SIZE bytes.
+ *
+ * \return - LZMA_OK: Decoding was successful.
+ * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
+ * buffer cannot be Stream Footer.
+ * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the footer
+ * is corrupt.
+ * - LZMA_HEADER_ERROR: Unsupported options are present
+ * in the footer.
+ */
+extern lzma_ret lzma_stream_footer_decode(
+ lzma_stream_flags *options, const uint8_t *in);
+
+
+/**
+ * \brief Compare two lzma_stream_flags structures
*
- * \return - LZMA_OK: Successfully initialized
- * - LZMA_MEM_ERROR: Cannot allocate memory
+ * index_size values are compared only if both are not LZMA_VLI_VALUE_UNKNOWN.
*
- * The actual decoding is done with lzma_code() and freed with lzma_end().
+ * \return true if both structures are considered equal; false otherwise.
*/
-extern lzma_ret lzma_stream_tail_decoder(
- lzma_stream *strm, lzma_stream_flags *options);
+extern lzma_bool lzma_stream_flags_equal(
+ const lzma_stream_flags *a, lzma_stream_flags *b);
diff --git a/src/liblzma/api/lzma/version.h b/src/liblzma/api/lzma/version.h
index d88aa305..252458a3 100644
--- a/src/liblzma/api/lzma/version.h
+++ b/src/liblzma/api/lzma/version.h
@@ -35,7 +35,7 @@
* \note The version number of LZMA Utils (and thus liblzma)
* has nothing to with the version number of LZMA SDK.
*/
-#define LZMA_VERSION UINT32_C(49990030)
+#define LZMA_VERSION UINT32_C(49990050)
/**
diff --git a/src/liblzma/api/lzma/vli.h b/src/liblzma/api/lzma/vli.h
index bc0770ce..15a9d0bf 100644
--- a/src/liblzma/api/lzma/vli.h
+++ b/src/liblzma/api/lzma/vli.h
@@ -158,25 +158,34 @@ typedef uint64_t lzma_vli;
* 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 vli_pos How many VLI-encoded bytes have already been written
+ * out. When starting to encode a new integer, *vli_pos
+ * must be set to zero. To use single-call encoding,
+ * set vli_pos to NULL.
* \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
+ * \return Slightly different return values are used in multi-call and
+ * single-call modes.
+ *
+ * Multi-call (vli_pos != NULL):
+ * - 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.
+ * - LZMA_PROG_ERROR: Arguments are not sane. This can be due
+ * to no *out_pos == out_size; this function doesn't use
+ * LZMA_BUF_ERROR.
+ *
+ * Single-call (vli_pos == NULL):
+ * - LZMA_OK: Integer successfully encoded.
+ * - LZMA_PROG_ERROR: Arguments are not sane. This can be due
+ * to too little output space; this function doesn't use
+ * LZMA_BUF_ERROR.
*/
extern lzma_ret lzma_vli_encode(
- lzma_vli vli, size_t *lzma_restrict vli_pos, size_t vli_size,
+ lzma_vli vli, size_t *lzma_restrict vli_pos,
uint8_t *lzma_restrict out, size_t *lzma_restrict out_pos,
size_t out_size);
@@ -189,18 +198,30 @@ extern lzma_ret lzma_vli_encode(
* 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.
+ * be initialized to zero. To use single-call decoding,
+ * set this to NULL.
* \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
+ * \return Slightly different return values are used in multi-call and
+ * single-call modes.
+ *
+ * Multi-call (vli_pos != NULL):
+ * - 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.
+ * - LZMA_DATA_ERROR: Integer is corrupt.
+ * - LZMA_PROG_ERROR: Arguments are not sane. This can be
+ * due to *in_pos == in_size; this function doesn't use
+ * LZMA_BUF_ERROR.
+ *
+ * Single-call (vli_pos == NULL):
+ * - LZMA_OK: Integer successfully decoded.
+ * - LZMA_DATA_ERROR: Integer is corrupt.
+ * - LZMA_PROG_ERROR: Arguments are not sane. This can be due to
+ * too little input; this function doesn't use LZMA_BUF_ERROR.
*/
extern lzma_ret lzma_vli_decode(lzma_vli *lzma_restrict vli,
size_t *lzma_restrict vli_pos, const uint8_t *lzma_restrict in,
@@ -208,37 +229,9 @@ extern lzma_ret lzma_vli_decode(lzma_vli *lzma_restrict vli,
/**
- * \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
+ * \brief Gets the 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);
+extern uint32_t lzma_vli_size(lzma_vli vli);