Path: blob/master/Utilities/cmliblzma/liblzma/api/lzma/container.h
3158 views
/* SPDX-License-Identifier: 0BSD */12/**3* \file lzma/container.h4* \brief File formats5* \note Never include this file directly. Use <lzma.h> instead.6*/78/*9* Author: Lasse Collin10*/1112#ifndef LZMA_H_INTERNAL13# error Never include this file directly. Use <lzma.h> instead.14#endif151617/************18* Encoding *19************/2021/**22* \brief Default compression preset23*24* It's not straightforward to recommend a default preset, because in some25* cases keeping the resource usage relatively low is more important that26* getting the maximum compression ratio.27*/28#define LZMA_PRESET_DEFAULT UINT32_C(6)293031/**32* \brief Mask for preset level33*34* This is useful only if you need to extract the level from the preset35* variable. That should be rare.36*/37#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F)383940/*41* Preset flags42*43* Currently only one flag is defined.44*/4546/**47* \brief Extreme compression preset48*49* This flag modifies the preset to make the encoding significantly slower50* while improving the compression ratio only marginally. This is useful51* when you don't mind spending time to get as small result as possible.52*53* This flag doesn't affect the memory usage requirements of the decoder (at54* least not significantly). The memory usage of the encoder may be increased55* a little but only at the lowest preset levels (0-3).56*/57#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31)585960/**61* \brief Multithreading options62*/63typedef struct {64/**65* \brief Flags66*67* Set this to zero if no flags are wanted.68*69* Encoder: No flags are currently supported.70*71* Decoder: Bitwise-or of zero or more of the decoder flags:72* - LZMA_TELL_NO_CHECK73* - LZMA_TELL_UNSUPPORTED_CHECK74* - LZMA_TELL_ANY_CHECK75* - LZMA_IGNORE_CHECK76* - LZMA_CONCATENATED77* - LZMA_FAIL_FAST78*/79uint32_t flags;8081/**82* \brief Number of worker threads to use83*/84uint32_t threads;8586/**87* \brief Encoder only: Maximum uncompressed size of a Block88*89* The encoder will start a new .xz Block every block_size bytes.90* Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code()91* the caller may tell liblzma to start a new Block earlier.92*93* With LZMA2, a recommended block size is 2-4 times the LZMA294* dictionary size. With very small dictionaries, it is recommended95* to use at least 1 MiB block size for good compression ratio, even96* if this is more than four times the dictionary size. Note that97* these are only recommendations for typical use cases; feel free98* to use other values. Just keep in mind that using a block size99* less than the LZMA2 dictionary size is waste of RAM.100*101* Set this to 0 to let liblzma choose the block size depending102* on the compression options. For LZMA2 it will be 3*dict_size103* or 1 MiB, whichever is more.104*105* For each thread, about 3 * block_size bytes of memory will be106* allocated. This may change in later liblzma versions. If so,107* the memory usage will probably be reduced, not increased.108*/109uint64_t block_size;110111/**112* \brief Timeout to allow lzma_code() to return early113*114* Multithreading can make liblzma consume input and produce115* output in a very bursty way: it may first read a lot of input116* to fill internal buffers, then no input or output occurs for117* a while.118*119* In single-threaded mode, lzma_code() won't return until it has120* either consumed all the input or filled the output buffer. If121* this is done in multithreaded mode, it may cause a call122* lzma_code() to take even tens of seconds, which isn't acceptable123* in all applications.124*125* To avoid very long blocking times in lzma_code(), a timeout126* (in milliseconds) may be set here. If lzma_code() would block127* longer than this number of milliseconds, it will return with128* LZMA_OK. Reasonable values are 100 ms or more. The xz command129* line tool uses 300 ms.130*131* If long blocking times are acceptable, set timeout to a special132* value of 0. This will disable the timeout mechanism and will make133* lzma_code() block until all the input is consumed or the output134* buffer has been filled.135*136* \note Even with a timeout, lzma_code() might sometimes take137* a long time to return. No timing guarantees are made.138*/139uint32_t timeout;140141/**142* \brief Encoder only: Compression preset143*144* The preset is set just like with lzma_easy_encoder().145* The preset is ignored if filters below is non-NULL.146*/147uint32_t preset;148149/**150* \brief Encoder only: Filter chain (alternative to a preset)151*152* If this is NULL, the preset above is used. Otherwise the preset153* is ignored and the filter chain specified here is used.154*/155const lzma_filter *filters;156157/**158* \brief Encoder only: Integrity check type159*160* See check.h for available checks. The xz command line tool161* defaults to LZMA_CHECK_CRC64, which is a good choice if you162* are unsure.163*/164lzma_check check;165166/*167* Reserved space to allow possible future extensions without168* breaking the ABI. You should not touch these, because the names169* of these variables may change. These are and will never be used170* with the currently supported options, so it is safe to leave these171* uninitialized.172*/173/** \private Reserved member. */174lzma_reserved_enum reserved_enum1;175176/** \private Reserved member. */177lzma_reserved_enum reserved_enum2;178179/** \private Reserved member. */180lzma_reserved_enum reserved_enum3;181182/** \private Reserved member. */183uint32_t reserved_int1;184185/** \private Reserved member. */186uint32_t reserved_int2;187188/** \private Reserved member. */189uint32_t reserved_int3;190191/** \private Reserved member. */192uint32_t reserved_int4;193194/**195* \brief Memory usage limit to reduce the number of threads196*197* Encoder: Ignored.198*199* Decoder:200*201* If the number of threads has been set so high that more than202* memlimit_threading bytes of memory would be needed, the number203* of threads will be reduced so that the memory usage will not exceed204* memlimit_threading bytes. However, if memlimit_threading cannot205* be met even in single-threaded mode, then decoding will continue206* in single-threaded mode and memlimit_threading may be exceeded207* even by a large amount. That is, memlimit_threading will never make208* lzma_code() return LZMA_MEMLIMIT_ERROR. To truly cap the memory209* usage, see memlimit_stop below.210*211* Setting memlimit_threading to UINT64_MAX or a similar huge value212* means that liblzma is allowed to keep the whole compressed file213* and the whole uncompressed file in memory in addition to the memory214* needed by the decompressor data structures used by each thread!215* In other words, a reasonable value limit must be set here or it216* will cause problems sooner or later. If you have no idea what217* a reasonable value could be, try lzma_physmem() / 4 as a starting218* point. Setting this limit will never prevent decompression of219* a file; this will only reduce the number of threads.220*221* If memlimit_threading is greater than memlimit_stop, then the value222* of memlimit_stop will be used for both.223*/224uint64_t memlimit_threading;225226/**227* \brief Memory usage limit that should never be exceeded228*229* Encoder: Ignored.230*231* Decoder: If decompressing will need more than this amount of232* memory even in the single-threaded mode, then lzma_code() will233* return LZMA_MEMLIMIT_ERROR.234*/235uint64_t memlimit_stop;236237/** \private Reserved member. */238uint64_t reserved_int7;239240/** \private Reserved member. */241uint64_t reserved_int8;242243/** \private Reserved member. */244void *reserved_ptr1;245246/** \private Reserved member. */247void *reserved_ptr2;248249/** \private Reserved member. */250void *reserved_ptr3;251252/** \private Reserved member. */253void *reserved_ptr4;254255} lzma_mt;256257258/**259* \brief Calculate approximate memory usage of easy encoder260*261* This function is a wrapper for lzma_raw_encoder_memusage().262*263* \param preset Compression preset (level and possible flags)264*265* \return Number of bytes of memory required for the given266* preset when encoding or UINT64_MAX on error.267*/268extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)269lzma_nothrow lzma_attr_pure;270271272/**273* \brief Calculate approximate decoder memory usage of a preset274*275* This function is a wrapper for lzma_raw_decoder_memusage().276*277* \param preset Compression preset (level and possible flags)278*279* \return Number of bytes of memory required to decompress a file280* that was compressed using the given preset or UINT64_MAX281* on error.282*/283extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)284lzma_nothrow lzma_attr_pure;285286287/**288* \brief Initialize .xz Stream encoder using a preset number289*290* This function is intended for those who just want to use the basic features291* of liblzma (that is, most developers out there).292*293* If initialization fails (return value is not LZMA_OK), all the memory294* allocated for *strm by liblzma is always freed. Thus, there is no need295* to call lzma_end() after failed initialization.296*297* If initialization succeeds, use lzma_code() to do the actual encoding.298* Valid values for 'action' (the second argument of lzma_code()) are299* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,300* there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.301*302* \param strm Pointer to lzma_stream that is at least initialized303* with LZMA_STREAM_INIT.304* \param preset Compression preset to use. A preset consist of level305* number and zero or more flags. Usually flags aren't306* used, so preset is simply a number [0, 9] which match307* the options -0 ... -9 of the xz command line tool.308* Additional flags can be set using bitwise-or with309* the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.310* \param check Integrity check type to use. See check.h for available311* checks. The xz command line tool defaults to312* LZMA_CHECK_CRC64, which is a good choice if you are313* unsure. LZMA_CHECK_CRC32 is good too as long as the314* uncompressed file is not many gigabytes.315*316* \return Possible lzma_ret values:317* - LZMA_OK: Initialization succeeded. Use lzma_code() to318* encode your data.319* - LZMA_MEM_ERROR: Memory allocation failed.320* - LZMA_OPTIONS_ERROR: The given compression preset is not321* supported by this build of liblzma.322* - LZMA_UNSUPPORTED_CHECK: The given check type is not323* supported by this liblzma build.324* - LZMA_PROG_ERROR: One or more of the parameters have values325* that will never be valid. For example, strm == NULL.326*/327extern LZMA_API(lzma_ret) lzma_easy_encoder(328lzma_stream *strm, uint32_t preset, lzma_check check)329lzma_nothrow lzma_attr_warn_unused_result;330331332/**333* \brief Single-call .xz Stream encoding using a preset number334*335* The maximum required output buffer size can be calculated with336* lzma_stream_buffer_bound().337*338* \param preset Compression preset to use. See the description339* in lzma_easy_encoder().340* \param check Type of the integrity check to calculate from341* uncompressed data.342* \param allocator lzma_allocator for custom allocator functions.343* Set to NULL to use malloc() and free().344* \param in Beginning of the input buffer345* \param in_size Size of the input buffer346* \param[out] out Beginning of the output buffer347* \param[out] out_pos The next byte will be written to out[*out_pos].348* *out_pos is updated only if encoding succeeds.349* \param out_size Size of the out buffer; the first byte into350* which no data is written to is out[out_size].351*352* \return Possible lzma_ret values:353* - LZMA_OK: Encoding was successful.354* - LZMA_BUF_ERROR: Not enough output buffer space.355* - LZMA_UNSUPPORTED_CHECK356* - LZMA_OPTIONS_ERROR357* - LZMA_MEM_ERROR358* - LZMA_DATA_ERROR359* - LZMA_PROG_ERROR360*/361extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(362uint32_t preset, lzma_check check,363const lzma_allocator *allocator,364const uint8_t *in, size_t in_size,365uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;366367368/**369* \brief Initialize .xz Stream encoder using a custom filter chain370*371* \param strm Pointer to lzma_stream that is at least initialized372* with LZMA_STREAM_INIT.373* \param filters Array of filters terminated with374* .id == LZMA_VLI_UNKNOWN. See filters.h for more375* information.376* \param check Type of the integrity check to calculate from377* uncompressed data.378*379* \return Possible lzma_ret values:380* - LZMA_OK: Initialization was successful.381* - LZMA_MEM_ERROR382* - LZMA_UNSUPPORTED_CHECK383* - LZMA_OPTIONS_ERROR384* - LZMA_PROG_ERROR385*/386extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,387const lzma_filter *filters, lzma_check check)388lzma_nothrow lzma_attr_warn_unused_result;389390391/**392* \brief Calculate approximate memory usage of multithreaded .xz encoder393*394* Since doing the encoding in threaded mode doesn't affect the memory395* requirements of single-threaded decompressor, you can use396* lzma_easy_decoder_memusage(options->preset) or397* lzma_raw_decoder_memusage(options->filters) to calculate398* the decompressor memory requirements.399*400* \param options Compression options401*402* \return Number of bytes of memory required for encoding with the403* given options. If an error occurs, for example due to404* unsupported preset or filter chain, UINT64_MAX is returned.405*/406extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage(407const lzma_mt *options) lzma_nothrow lzma_attr_pure;408409410/**411* \brief Initialize multithreaded .xz Stream encoder412*413* This provides the functionality of lzma_easy_encoder() and414* lzma_stream_encoder() as a single function for multithreaded use.415*416* The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH,417* LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be418* added in the future.419*420* \param strm Pointer to lzma_stream that is at least initialized421* with LZMA_STREAM_INIT.422* \param options Pointer to multithreaded compression options423*424* \return Possible lzma_ret values:425* - LZMA_OK426* - LZMA_MEM_ERROR427* - LZMA_UNSUPPORTED_CHECK428* - LZMA_OPTIONS_ERROR429* - LZMA_PROG_ERROR430*/431extern LZMA_API(lzma_ret) lzma_stream_encoder_mt(432lzma_stream *strm, const lzma_mt *options)433lzma_nothrow lzma_attr_warn_unused_result;434435436/**437* \brief Calculate recommended Block size for multithreaded .xz encoder438*439* This calculates a recommended Block size for multithreaded encoding given440* a filter chain. This is used internally by lzma_stream_encoder_mt() to441* determine the Block size if the block_size member is not set to the442* special value of 0 in the lzma_mt options struct.443*444* If one wishes to change the filters between Blocks, this function is445* helpful to set the block_size member of the lzma_mt struct before calling446* lzma_stream_encoder_mt(). Since the block_size member represents the447* maximum possible Block size for the multithreaded .xz encoder, one can448* use this function to find the maximum recommended Block size based on449* all planned filter chains. Otherwise, the multithreaded encoder will450* base its maximum Block size on the first filter chain used (if the451* block_size member is not set), which may unnecessarily limit the Block452* size for a later filter chain.453*454* \param filters Array of filters terminated with455* .id == LZMA_VLI_UNKNOWN.456*457* \return Recommended Block size in bytes, or UINT64_MAX if458* an error occurred.459*/460extern LZMA_API(uint64_t) lzma_mt_block_size(const lzma_filter *filters)461lzma_nothrow;462463464/**465* \brief Initialize .lzma encoder (legacy file format)466*467* The .lzma format is sometimes called the LZMA_Alone format, which is the468* reason for the name of this function. The .lzma format supports only the469* LZMA1 filter. There is no support for integrity checks like CRC32.470*471* Use this function if and only if you need to create files readable by472* legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format473* is strongly recommended.474*475* The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH.476* No kind of flushing is supported, because the file format doesn't make477* it possible.478*479* \param strm Pointer to lzma_stream that is at least initialized480* with LZMA_STREAM_INIT.481* \param options Pointer to encoder options482*483* \return Possible lzma_ret values:484* - LZMA_OK485* - LZMA_MEM_ERROR486* - LZMA_OPTIONS_ERROR487* - LZMA_PROG_ERROR488*/489extern LZMA_API(lzma_ret) lzma_alone_encoder(490lzma_stream *strm, const lzma_options_lzma *options)491lzma_nothrow lzma_attr_warn_unused_result;492493494/**495* \brief Calculate output buffer size for single-call Stream encoder496*497* When trying to compress incompressible data, the encoded size will be498* slightly bigger than the input data. This function calculates how much499* output buffer space is required to be sure that lzma_stream_buffer_encode()500* doesn't return LZMA_BUF_ERROR.501*502* The calculated value is not exact, but it is guaranteed to be big enough.503* The actual maximum output space required may be slightly smaller (up to504* about 100 bytes). This should not be a problem in practice.505*506* If the calculated maximum size doesn't fit into size_t or would make the507* Stream grow past LZMA_VLI_MAX (which should never happen in practice),508* zero is returned to indicate the error.509*510* \note The limit calculated by this function applies only to511* single-call encoding. Multi-call encoding may (and probably512* will) have larger maximum expansion when encoding513* incompressible data. Currently there is no function to514* calculate the maximum expansion of multi-call encoding.515*516* \param uncompressed_size Size in bytes of the uncompressed517* input data518*519* \return Maximum number of bytes needed to store the compressed data.520*/521extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)522lzma_nothrow;523524525/**526* \brief Single-call .xz Stream encoder527*528* \param filters Array of filters terminated with529* .id == LZMA_VLI_UNKNOWN. See filters.h for more530* information.531* \param check Type of the integrity check to calculate from532* uncompressed data.533* \param allocator lzma_allocator for custom allocator functions.534* Set to NULL to use malloc() and free().535* \param in Beginning of the input buffer536* \param in_size Size of the input buffer537* \param[out] out Beginning of the output buffer538* \param[out] out_pos The next byte will be written to out[*out_pos].539* *out_pos is updated only if encoding succeeds.540* \param out_size Size of the out buffer; the first byte into541* which no data is written to is out[out_size].542*543* \return Possible lzma_ret values:544* - LZMA_OK: Encoding was successful.545* - LZMA_BUF_ERROR: Not enough output buffer space.546* - LZMA_UNSUPPORTED_CHECK547* - LZMA_OPTIONS_ERROR548* - LZMA_MEM_ERROR549* - LZMA_DATA_ERROR550* - LZMA_PROG_ERROR551*/552extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(553lzma_filter *filters, lzma_check check,554const lzma_allocator *allocator,555const uint8_t *in, size_t in_size,556uint8_t *out, size_t *out_pos, size_t out_size)557lzma_nothrow lzma_attr_warn_unused_result;558559560/**561* \brief MicroLZMA encoder562*563* The MicroLZMA format is a raw LZMA stream whose first byte (always 0x00)564* has been replaced with bitwise-negation of the LZMA properties (lc/lp/pb).565* This encoding ensures that the first byte of MicroLZMA stream is never566* 0x00. There is no end of payload marker and thus the uncompressed size567* must be stored separately. For the best error detection the dictionary568* size should be stored separately as well but alternatively one may use569* the uncompressed size as the dictionary size when decoding.570*571* With the MicroLZMA encoder, lzma_code() behaves slightly unusually.572* The action argument must be LZMA_FINISH and the return value will never be573* LZMA_OK. Thus the encoding is always done with a single lzma_code() after574* the initialization. The benefit of the combination of initialization575* function and lzma_code() is that memory allocations can be re-used for576* better performance.577*578* lzma_code() will try to encode as much input as is possible to fit into579* the given output buffer. If not all input can be encoded, the stream will580* be finished without encoding all the input. The caller must check both581* input and output buffer usage after lzma_code() (total_in and total_out582* in lzma_stream can be convenient). Often lzma_code() can fill the output583* buffer completely if there is a lot of input, but sometimes a few bytes584* may remain unused because the next LZMA symbol would require more space.585*586* lzma_stream.avail_out must be at least 6. Otherwise LZMA_PROG_ERROR587* will be returned.588*589* The LZMA dictionary should be reasonably low to speed up the encoder590* re-initialization. A good value is bigger than the resulting591* uncompressed size of most of the output chunks. For example, if output592* size is 4 KiB, dictionary size of 32 KiB or 64 KiB is good. If the593* data compresses extremely well, even 128 KiB may be useful.594*595* The MicroLZMA format and this encoder variant were made with the EROFS596* file system in mind. This format may be convenient in other embedded597* uses too where many small streams are needed. XZ Embedded includes a598* decoder for this format.599*600* \param strm Pointer to lzma_stream that is at least initialized601* with LZMA_STREAM_INIT.602* \param options Pointer to encoder options603*604* \return Possible lzma_ret values:605* - LZMA_STREAM_END: All good. Check the amounts of input used606* and output produced. Store the amount of input used607* (uncompressed size) as it needs to be known to decompress608* the data.609* - LZMA_OPTIONS_ERROR610* - LZMA_MEM_ERROR611* - LZMA_PROG_ERROR: In addition to the generic reasons for this612* error code, this may also be returned if there isn't enough613* output space (6 bytes) to create a valid MicroLZMA stream.614*/615extern LZMA_API(lzma_ret) lzma_microlzma_encoder(616lzma_stream *strm, const lzma_options_lzma *options)617lzma_nothrow;618619620/************621* Decoding *622************/623624/**625* This flag makes lzma_code() return LZMA_NO_CHECK if the input stream626* being decoded has no integrity check. Note that when used with627* lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK628* if LZMA_TELL_NO_CHECK is used.629*/630#define LZMA_TELL_NO_CHECK UINT32_C(0x01)631632633/**634* This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input635* stream has an integrity check, but the type of the integrity check is not636* supported by this liblzma version or build. Such files can still be637* decoded, but the integrity check cannot be verified.638*/639#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02)640641642/**643* This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type644* of the integrity check is known. The type can then be got with645* lzma_get_check().646*/647#define LZMA_TELL_ANY_CHECK UINT32_C(0x04)648649650/**651* This flag makes lzma_code() not calculate and verify the integrity check652* of the compressed data in .xz files. This means that invalid integrity653* check values won't be detected and LZMA_DATA_ERROR won't be returned in654* such cases.655*656* This flag only affects the checks of the compressed data itself; the CRC32657* values in the .xz headers will still be verified normally.658*659* Don't use this flag unless you know what you are doing. Possible reasons660* to use this flag:661*662* - Trying to recover data from a corrupt .xz file.663*664* - Speeding up decompression, which matters mostly with SHA-256665* or with files that have compressed extremely well. It's recommended666* to not use this flag for this purpose unless the file integrity is667* verified externally in some other way.668*669* Support for this flag was added in liblzma 5.1.4beta.670*/671#define LZMA_IGNORE_CHECK UINT32_C(0x10)672673674/**675* This flag enables decoding of concatenated files with file formats that676* allow concatenating compressed files as is. From the formats currently677* supported by liblzma, only the .xz and .lz formats allow concatenated678* files. Concatenated files are not allowed with the legacy .lzma format.679*680* This flag also affects the usage of the 'action' argument for lzma_code().681* When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END682* unless LZMA_FINISH is used as 'action'. Thus, the application has to set683* LZMA_FINISH in the same way as it does when encoding.684*685* If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH686* as 'action' for lzma_code(), but the usage of LZMA_FINISH isn't required.687*/688#define LZMA_CONCATENATED UINT32_C(0x08)689690691/**692* This flag makes the threaded decoder report errors (like LZMA_DATA_ERROR)693* as soon as they are detected. This saves time when the application has no694* interest in a partially decompressed truncated or corrupt file. Note that695* due to timing randomness, if the same truncated or corrupt input is696* decompressed multiple times with this flag, a different amount of output697* may be produced by different runs, and even the error code might vary.698*699* When using LZMA_FAIL_FAST, it is recommended to use LZMA_FINISH to tell700* the decoder when no more input will be coming because it can help fast701* detection and reporting of truncated files. Note that in this situation702* truncated files might be diagnosed with LZMA_DATA_ERROR instead of703* LZMA_OK or LZMA_BUF_ERROR!704*705* Without this flag the threaded decoder will provide as much output as706* possible at first and then report the pending error. This default behavior707* matches the single-threaded decoder and provides repeatable behavior708* with truncated or corrupt input. There are a few special cases where the709* behavior can still differ like memory allocation failures (LZMA_MEM_ERROR).710*711* Single-threaded decoders currently ignore this flag.712*713* Support for this flag was added in liblzma 5.3.3alpha. Note that in older714* versions this flag isn't supported (LZMA_OPTIONS_ERROR) even by functions715* that ignore this flag in newer liblzma versions.716*/717#define LZMA_FAIL_FAST UINT32_C(0x20)718719720/**721* \brief Initialize .xz Stream decoder722*723* \param strm Pointer to lzma_stream that is at least initialized724* with LZMA_STREAM_INIT.725* \param memlimit Memory usage limit as bytes. Use UINT64_MAX726* to effectively disable the limiter. liblzma727* 5.2.3 and earlier don't allow 0 here and return728* LZMA_PROG_ERROR; later versions treat 0 as if 1729* had been specified.730* \param flags Bitwise-or of zero or more of the decoder flags:731* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,732* LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,733* LZMA_CONCATENATED, LZMA_FAIL_FAST734*735* \return Possible lzma_ret values:736* - LZMA_OK: Initialization was successful.737* - LZMA_MEM_ERROR: Cannot allocate memory.738* - LZMA_OPTIONS_ERROR: Unsupported flags739* - LZMA_PROG_ERROR740*/741extern LZMA_API(lzma_ret) lzma_stream_decoder(742lzma_stream *strm, uint64_t memlimit, uint32_t flags)743lzma_nothrow lzma_attr_warn_unused_result;744745746/**747* \brief Initialize multithreaded .xz Stream decoder748*749* The decoder can decode multiple Blocks in parallel. This requires that each750* Block Header contains the Compressed Size and Uncompressed size fields751* which are added by the multi-threaded encoder, see lzma_stream_encoder_mt().752*753* A Stream with one Block will only utilize one thread. A Stream with multiple754* Blocks but without size information in Block Headers will be processed in755* single-threaded mode in the same way as done by lzma_stream_decoder().756* Concatenated Streams are processed one Stream at a time; no inter-Stream757* parallelization is done.758*759* This function behaves like lzma_stream_decoder() when options->threads == 1760* and options->memlimit_threading <= 1.761*762* \param strm Pointer to lzma_stream that is at least initialized763* with LZMA_STREAM_INIT.764* \param options Pointer to multithreaded compression options765*766* \return Possible lzma_ret values:767* - LZMA_OK: Initialization was successful.768* - LZMA_MEM_ERROR: Cannot allocate memory.769* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.770* - LZMA_OPTIONS_ERROR: Unsupported flags.771* - LZMA_PROG_ERROR772*/773extern LZMA_API(lzma_ret) lzma_stream_decoder_mt(774lzma_stream *strm, const lzma_mt *options)775lzma_nothrow lzma_attr_warn_unused_result;776777778/**779* \brief Decode .xz, .lzma, and .lz (lzip) files with autodetection780*781* This decoder autodetects between the .xz, .lzma, and .lz file formats,782* and calls lzma_stream_decoder(), lzma_alone_decoder(), or783* lzma_lzip_decoder() once the type of the input file has been detected.784*785* Support for .lz was added in 5.4.0.786*787* If the flag LZMA_CONCATENATED is used and the input is a .lzma file:788* For historical reasons concatenated .lzma files aren't supported.789* If there is trailing data after one .lzma stream, lzma_code() will790* return LZMA_DATA_ERROR. (lzma_alone_decoder() doesn't have such a check791* as it doesn't support any decoder flags. It will return LZMA_STREAM_END792* after one .lzma stream.)793*794* \param strm Pointer to lzma_stream that is at least initialized795* with LZMA_STREAM_INIT.796* \param memlimit Memory usage limit as bytes. Use UINT64_MAX797* to effectively disable the limiter. liblzma798* 5.2.3 and earlier don't allow 0 here and return799* LZMA_PROG_ERROR; later versions treat 0 as if 1800* had been specified.801* \param flags Bitwise-or of zero or more of the decoder flags:802* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,803* LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,804* LZMA_CONCATENATED, LZMA_FAIL_FAST805*806* \return Possible lzma_ret values:807* - LZMA_OK: Initialization was successful.808* - LZMA_MEM_ERROR: Cannot allocate memory.809* - LZMA_OPTIONS_ERROR: Unsupported flags810* - LZMA_PROG_ERROR811*/812extern LZMA_API(lzma_ret) lzma_auto_decoder(813lzma_stream *strm, uint64_t memlimit, uint32_t flags)814lzma_nothrow lzma_attr_warn_unused_result;815816817/**818* \brief Initialize .lzma decoder (legacy file format)819*820* Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.821* There is no need to use LZMA_FINISH, but it's allowed because it may822* simplify certain types of applications.823*824* \param strm Pointer to lzma_stream that is at least initialized825* with LZMA_STREAM_INIT.826* \param memlimit Memory usage limit as bytes. Use UINT64_MAX827* to effectively disable the limiter. liblzma828* 5.2.3 and earlier don't allow 0 here and return829* LZMA_PROG_ERROR; later versions treat 0 as if 1830* had been specified.831*832* \return Possible lzma_ret values:833* - LZMA_OK834* - LZMA_MEM_ERROR835* - LZMA_PROG_ERROR836*/837extern LZMA_API(lzma_ret) lzma_alone_decoder(838lzma_stream *strm, uint64_t memlimit)839lzma_nothrow lzma_attr_warn_unused_result;840841842/**843* \brief Initialize .lz (lzip) decoder (a foreign file format)844*845* This decoder supports the .lz format version 0 and the unextended .lz846* format version 1:847*848* - Files in the format version 0 were produced by lzip 1.3 and older.849* Such files aren't common but may be found from file archives850* as a few source packages were released in this format. People851* might have old personal files in this format too. Decompression852* support for the format version 0 was removed in lzip 1.18.853*854* - lzip 1.3 added decompression support for .lz format version 1 files.855* Compression support was added in lzip 1.4. In lzip 1.6 the .lz format856* version 1 was extended to support the Sync Flush marker. This extension857* is not supported by liblzma. lzma_code() will return LZMA_DATA_ERROR858* at the location of the Sync Flush marker. In practice files with859* the Sync Flush marker are very rare and thus liblzma can decompress860* almost all .lz files.861*862* Just like with lzma_stream_decoder() for .xz files, LZMA_CONCATENATED863* should be used when decompressing normal standalone .lz files.864*865* The .lz format allows putting non-.lz data at the end of a file after at866* least one valid .lz member. That is, one can append custom data at the end867* of a .lz file and the decoder is required to ignore it. In liblzma this868* is relevant only when LZMA_CONCATENATED is used. In that case lzma_code()869* will return LZMA_STREAM_END and leave lzma_stream.next_in pointing to870* the first byte of the non-.lz data. An exception to this is if the first871* 1-3 bytes of the non-.lz data are identical to the .lz magic bytes872* (0x4C, 0x5A, 0x49, 0x50; "LZIP" in US-ASCII). In such a case the 1-3 bytes873* will have been ignored by lzma_code(). If one wishes to locate the non-.lz874* data reliably, one must ensure that the first byte isn't 0x4C. Actually875* one should ensure that none of the first four bytes of trailing data are876* equal to the magic bytes because lzip >= 1.20 requires it by default.877*878* \param strm Pointer to lzma_stream that is at least initialized879* with LZMA_STREAM_INIT.880* \param memlimit Memory usage limit as bytes. Use UINT64_MAX881* to effectively disable the limiter.882* \param flags Bitwise-or of flags, or zero for no flags.883* All decoder flags listed above are supported884* although only LZMA_CONCATENATED and (in very rare885* cases) LZMA_IGNORE_CHECK are actually useful.886* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,887* and LZMA_FAIL_FAST do nothing. LZMA_TELL_ANY_CHECK888* is supported for consistency only as CRC32 is889* always used in the .lz format.890*891* \return Possible lzma_ret values:892* - LZMA_OK: Initialization was successful.893* - LZMA_MEM_ERROR: Cannot allocate memory.894* - LZMA_OPTIONS_ERROR: Unsupported flags895* - LZMA_PROG_ERROR896*/897extern LZMA_API(lzma_ret) lzma_lzip_decoder(898lzma_stream *strm, uint64_t memlimit, uint32_t flags)899lzma_nothrow lzma_attr_warn_unused_result;900901902/**903* \brief Single-call .xz Stream decoder904*905* \param memlimit Pointer to how much memory the decoder is allowed906* to allocate. The value pointed by this pointer is907* modified if and only if LZMA_MEMLIMIT_ERROR is908* returned.909* \param flags Bitwise-or of zero or more of the decoder flags:910* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,911* LZMA_IGNORE_CHECK, LZMA_CONCATENATED,912* LZMA_FAIL_FAST. Note that LZMA_TELL_ANY_CHECK913* is not allowed and will return LZMA_PROG_ERROR.914* \param allocator lzma_allocator for custom allocator functions.915* Set to NULL to use malloc() and free().916* \param in Beginning of the input buffer917* \param in_pos The next byte will be read from in[*in_pos].918* *in_pos is updated only if decoding succeeds.919* \param in_size Size of the input buffer; the first byte that920* won't be read is in[in_size].921* \param[out] out Beginning of the output buffer922* \param[out] out_pos The next byte will be written to out[*out_pos].923* *out_pos is updated only if decoding succeeds.924* \param out_size Size of the out buffer; the first byte into925* which no data is written to is out[out_size].926*927* \return Possible lzma_ret values:928* - LZMA_OK: Decoding was successful.929* - LZMA_FORMAT_ERROR930* - LZMA_OPTIONS_ERROR931* - LZMA_DATA_ERROR932* - LZMA_NO_CHECK: This can be returned only if using933* the LZMA_TELL_NO_CHECK flag.934* - LZMA_UNSUPPORTED_CHECK: This can be returned only if using935* the LZMA_TELL_UNSUPPORTED_CHECK flag.936* - LZMA_MEM_ERROR937* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.938* The minimum required memlimit value was stored to *memlimit.939* - LZMA_BUF_ERROR: Output buffer was too small.940* - LZMA_PROG_ERROR941*/942extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(943uint64_t *memlimit, uint32_t flags,944const lzma_allocator *allocator,945const uint8_t *in, size_t *in_pos, size_t in_size,946uint8_t *out, size_t *out_pos, size_t out_size)947lzma_nothrow lzma_attr_warn_unused_result;948949950/**951* \brief MicroLZMA decoder952*953* See lzma_microlzma_encoder() for more information.954*955* The lzma_code() usage with this decoder is completely normal. The956* special behavior of lzma_code() applies to lzma_microlzma_encoder() only.957*958* \param strm Pointer to lzma_stream that is at least initialized959* with LZMA_STREAM_INIT.960* \param comp_size Compressed size of the MicroLZMA stream.961* The caller must somehow know this exactly.962* \param uncomp_size Uncompressed size of the MicroLZMA stream.963* If the exact uncompressed size isn't known, this964* can be set to a value that is at most as big as965* the exact uncompressed size would be, but then the966* next argument uncomp_size_is_exact must be false.967* \param uncomp_size_is_exact968* If true, uncomp_size must be exactly correct.969* This will improve error detection at the end of970* the stream. If the exact uncompressed size isn't971* known, this must be false. uncomp_size must still972* be at most as big as the exact uncompressed size973* is. Setting this to false when the exact size is974* known will work but error detection at the end of975* the stream will be weaker.976* \param dict_size LZMA dictionary size that was used when977* compressing the data. It is OK to use a bigger978* value too but liblzma will then allocate more979* memory than would actually be required and error980* detection will be slightly worse. (Note that with981* the implementation in XZ Embedded it doesn't982* affect the memory usage if one specifies bigger983* dictionary than actually required.)984*985* \return Possible lzma_ret values:986* - LZMA_OK987* - LZMA_MEM_ERROR988* - LZMA_OPTIONS_ERROR989* - LZMA_PROG_ERROR990*/991extern LZMA_API(lzma_ret) lzma_microlzma_decoder(992lzma_stream *strm, uint64_t comp_size,993uint64_t uncomp_size, lzma_bool uncomp_size_is_exact,994uint32_t dict_size) lzma_nothrow;995996997