1207753Smm/** 2207753Smm * \file lzma/container.h 3207753Smm * \brief File formats 4207753Smm */ 5207753Smm 6207753Smm/* 7207753Smm * Author: Lasse Collin 8207753Smm * 9207753Smm * This file has been put into the public domain. 10207753Smm * You can do whatever you want with this file. 11207753Smm * 12207753Smm * See ../lzma.h for information about liblzma as a whole. 13207753Smm */ 14207753Smm 15207753Smm#ifndef LZMA_H_INTERNAL 16207753Smm# error Never include this file directly. Use <lzma.h> instead. 17207753Smm#endif 18207753Smm 19207753Smm 20207753Smm/************ 21207753Smm * Encoding * 22207753Smm ************/ 23207753Smm 24207753Smm/** 25207753Smm * \brief Default compression preset 26207753Smm * 27207753Smm * It's not straightforward to recommend a default preset, because in some 28207753Smm * cases keeping the resource usage relatively low is more important that 29207753Smm * getting the maximum compression ratio. 30207753Smm */ 31207753Smm#define LZMA_PRESET_DEFAULT UINT32_C(6) 32207753Smm 33207753Smm 34207753Smm/** 35207753Smm * \brief Mask for preset level 36207753Smm * 37207753Smm * This is useful only if you need to extract the level from the preset 38207753Smm * variable. That should be rare. 39207753Smm */ 40207753Smm#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) 41207753Smm 42207753Smm 43207753Smm/* 44207753Smm * Preset flags 45207753Smm * 46207753Smm * Currently only one flag is defined. 47207753Smm */ 48207753Smm 49207753Smm/** 50207753Smm * \brief Extreme compression preset 51207753Smm * 52207753Smm * This flag modifies the preset to make the encoding significantly slower 53207753Smm * while improving the compression ratio only marginally. This is useful 54207753Smm * when you don't mind wasting time to get as small result as possible. 55207753Smm * 56207753Smm * This flag doesn't affect the memory usage requirements of the decoder (at 57207753Smm * least not significantly). The memory usage of the encoder may be increased 58215187Smm * a little but only at the lowest preset levels (0-3). 59207753Smm */ 60207753Smm#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) 61207753Smm 62207753Smm 63207753Smm/** 64278433Srpaulo * \brief Multithreading options 65278433Srpaulo */ 66278433Srpaulotypedef struct { 67278433Srpaulo /** 68278433Srpaulo * \brief Flags 69278433Srpaulo * 70278433Srpaulo * Set this to zero if no flags are wanted. 71278433Srpaulo * 72278433Srpaulo * No flags are currently supported. 73278433Srpaulo */ 74278433Srpaulo uint32_t flags; 75278433Srpaulo 76278433Srpaulo /** 77278433Srpaulo * \brief Number of worker threads to use 78278433Srpaulo */ 79278433Srpaulo uint32_t threads; 80278433Srpaulo 81278433Srpaulo /** 82278433Srpaulo * \brief Maximum uncompressed size of a Block 83278433Srpaulo * 84278433Srpaulo * The encoder will start a new .xz Block every block_size bytes. 85278433Srpaulo * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code() 86278433Srpaulo * the caller may tell liblzma to start a new Block earlier. 87278433Srpaulo * 88278433Srpaulo * With LZMA2, a recommended block size is 2-4 times the LZMA2 89278433Srpaulo * dictionary size. With very small dictionaries, it is recommended 90278433Srpaulo * to use at least 1 MiB block size for good compression ratio, even 91278433Srpaulo * if this is more than four times the dictionary size. Note that 92278433Srpaulo * these are only recommendations for typical use cases; feel free 93278433Srpaulo * to use other values. Just keep in mind that using a block size 94278433Srpaulo * less than the LZMA2 dictionary size is waste of RAM. 95278433Srpaulo * 96278433Srpaulo * Set this to 0 to let liblzma choose the block size depending 97278433Srpaulo * on the compression options. For LZMA2 it will be 3*dict_size 98278433Srpaulo * or 1 MiB, whichever is more. 99278433Srpaulo * 100278433Srpaulo * For each thread, about 3 * block_size bytes of memory will be 101278433Srpaulo * allocated. This may change in later liblzma versions. If so, 102278433Srpaulo * the memory usage will probably be reduced, not increased. 103278433Srpaulo */ 104278433Srpaulo uint64_t block_size; 105278433Srpaulo 106278433Srpaulo /** 107278433Srpaulo * \brief Timeout to allow lzma_code() to return early 108278433Srpaulo * 109278433Srpaulo * Multithreading can make liblzma to consume input and produce 110278433Srpaulo * output in a very bursty way: it may first read a lot of input 111278433Srpaulo * to fill internal buffers, then no input or output occurs for 112278433Srpaulo * a while. 113278433Srpaulo * 114278433Srpaulo * In single-threaded mode, lzma_code() won't return until it has 115278433Srpaulo * either consumed all the input or filled the output buffer. If 116278433Srpaulo * this is done in multithreaded mode, it may cause a call 117278433Srpaulo * lzma_code() to take even tens of seconds, which isn't acceptable 118278433Srpaulo * in all applications. 119278433Srpaulo * 120278433Srpaulo * To avoid very long blocking times in lzma_code(), a timeout 121278433Srpaulo * (in milliseconds) may be set here. If lzma_code() would block 122278433Srpaulo * longer than this number of milliseconds, it will return with 123278433Srpaulo * LZMA_OK. Reasonable values are 100 ms or more. The xz command 124278433Srpaulo * line tool uses 300 ms. 125278433Srpaulo * 126278433Srpaulo * If long blocking times are fine for you, set timeout to a special 127278433Srpaulo * value of 0, which will disable the timeout mechanism and will make 128278433Srpaulo * lzma_code() block until all the input is consumed or the output 129278433Srpaulo * buffer has been filled. 130278433Srpaulo * 131278433Srpaulo * \note Even with a timeout, lzma_code() might sometimes take 132278433Srpaulo * somewhat long time to return. No timing guarantees 133278433Srpaulo * are made. 134278433Srpaulo */ 135278433Srpaulo uint32_t timeout; 136278433Srpaulo 137278433Srpaulo /** 138278433Srpaulo * \brief Compression preset (level and possible flags) 139278433Srpaulo * 140278433Srpaulo * The preset is set just like with lzma_easy_encoder(). 141278433Srpaulo * The preset is ignored if filters below is non-NULL. 142278433Srpaulo */ 143278433Srpaulo uint32_t preset; 144278433Srpaulo 145278433Srpaulo /** 146278433Srpaulo * \brief Filter chain (alternative to a preset) 147278433Srpaulo * 148278433Srpaulo * If this is NULL, the preset above is used. Otherwise the preset 149278433Srpaulo * is ignored and the filter chain specified here is used. 150278433Srpaulo */ 151278433Srpaulo const lzma_filter *filters; 152278433Srpaulo 153278433Srpaulo /** 154278433Srpaulo * \brief Integrity check type 155278433Srpaulo * 156278433Srpaulo * See check.h for available checks. The xz command line tool 157278433Srpaulo * defaults to LZMA_CHECK_CRC64, which is a good choice if you 158278433Srpaulo * are unsure. 159278433Srpaulo */ 160278433Srpaulo lzma_check check; 161278433Srpaulo 162278433Srpaulo /* 163278433Srpaulo * Reserved space to allow possible future extensions without 164278433Srpaulo * breaking the ABI. You should not touch these, because the names 165278433Srpaulo * of these variables may change. These are and will never be used 166278433Srpaulo * with the currently supported options, so it is safe to leave these 167278433Srpaulo * uninitialized. 168278433Srpaulo */ 169278433Srpaulo lzma_reserved_enum reserved_enum1; 170278433Srpaulo lzma_reserved_enum reserved_enum2; 171278433Srpaulo lzma_reserved_enum reserved_enum3; 172278433Srpaulo uint32_t reserved_int1; 173278433Srpaulo uint32_t reserved_int2; 174278433Srpaulo uint32_t reserved_int3; 175278433Srpaulo uint32_t reserved_int4; 176278433Srpaulo uint64_t reserved_int5; 177278433Srpaulo uint64_t reserved_int6; 178278433Srpaulo uint64_t reserved_int7; 179278433Srpaulo uint64_t reserved_int8; 180278433Srpaulo void *reserved_ptr1; 181278433Srpaulo void *reserved_ptr2; 182278433Srpaulo void *reserved_ptr3; 183278433Srpaulo void *reserved_ptr4; 184278433Srpaulo 185278433Srpaulo} lzma_mt; 186278433Srpaulo 187278433Srpaulo 188278433Srpaulo/** 189215187Smm * \brief Calculate approximate memory usage of easy encoder 190207753Smm * 191207753Smm * This function is a wrapper for lzma_raw_encoder_memusage(). 192207753Smm * 193207753Smm * \param preset Compression preset (level and possible flags) 194223935Smm * 195223935Smm * \return Number of bytes of memory required for the given 196223935Smm * preset when encoding. If an error occurs, for example 197223935Smm * due to unsupported preset, UINT64_MAX is returned. 198207753Smm */ 199207753Smmextern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) 200207753Smm lzma_nothrow lzma_attr_pure; 201207753Smm 202207753Smm 203207753Smm/** 204215187Smm * \brief Calculate approximate decoder memory usage of a preset 205207753Smm * 206207753Smm * This function is a wrapper for lzma_raw_decoder_memusage(). 207207753Smm * 208207753Smm * \param preset Compression preset (level and possible flags) 209223935Smm * 210223935Smm * \return Number of bytes of memory required to decompress a file 211223935Smm * that was compressed using the given preset. If an error 212223935Smm * occurs, for example due to unsupported preset, UINT64_MAX 213223935Smm * is returned. 214207753Smm */ 215207753Smmextern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) 216207753Smm lzma_nothrow lzma_attr_pure; 217207753Smm 218207753Smm 219207753Smm/** 220207753Smm * \brief Initialize .xz Stream encoder using a preset number 221207753Smm * 222207753Smm * This function is intended for those who just want to use the basic features 223207753Smm * if liblzma (that is, most developers out there). 224207753Smm * 225207753Smm * \param strm Pointer to lzma_stream that is at least initialized 226207753Smm * with LZMA_STREAM_INIT. 227207753Smm * \param preset Compression preset to use. A preset consist of level 228207753Smm * number and zero or more flags. Usually flags aren't 229207753Smm * used, so preset is simply a number [0, 9] which match 230215187Smm * the options -0 ... -9 of the xz command line tool. 231207753Smm * Additional flags can be be set using bitwise-or with 232207753Smm * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME. 233207753Smm * \param check Integrity check type to use. See check.h for available 234215187Smm * checks. The xz command line tool defaults to 235215187Smm * LZMA_CHECK_CRC64, which is a good choice if you are 236215187Smm * unsure. LZMA_CHECK_CRC32 is good too as long as the 237215187Smm * uncompressed file is not many gigabytes. 238207753Smm * 239207753Smm * \return - LZMA_OK: Initialization succeeded. Use lzma_code() to 240207753Smm * encode your data. 241207753Smm * - LZMA_MEM_ERROR: Memory allocation failed. 242215187Smm * - LZMA_OPTIONS_ERROR: The given compression preset is not 243207753Smm * supported by this build of liblzma. 244207753Smm * - LZMA_UNSUPPORTED_CHECK: The given check type is not 245207753Smm * supported by this liblzma build. 246207753Smm * - LZMA_PROG_ERROR: One or more of the parameters have values 247207753Smm * that will never be valid. For example, strm == NULL. 248207753Smm * 249207753Smm * If initialization fails (return value is not LZMA_OK), all the memory 250207753Smm * allocated for *strm by liblzma is always freed. Thus, there is no need 251207753Smm * to call lzma_end() after failed initialization. 252207753Smm * 253207753Smm * If initialization succeeds, use lzma_code() to do the actual encoding. 254207753Smm * Valid values for `action' (the second argument of lzma_code()) are 255207753Smm * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, 256207753Smm * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH. 257207753Smm */ 258207753Smmextern LZMA_API(lzma_ret) lzma_easy_encoder( 259207753Smm lzma_stream *strm, uint32_t preset, lzma_check check) 260207753Smm lzma_nothrow lzma_attr_warn_unused_result; 261207753Smm 262207753Smm 263207753Smm/** 264207753Smm * \brief Single-call .xz Stream encoding using a preset number 265207753Smm * 266207753Smm * The maximum required output buffer size can be calculated with 267207753Smm * lzma_stream_buffer_bound(). 268207753Smm * 269207753Smm * \param preset Compression preset to use. See the description 270207753Smm * in lzma_easy_encoder(). 271207753Smm * \param check Type of the integrity check to calculate from 272207753Smm * uncompressed data. 273207753Smm * \param allocator lzma_allocator for custom allocator functions. 274207753Smm * Set to NULL to use malloc() and free(). 275207753Smm * \param in Beginning of the input buffer 276207753Smm * \param in_size Size of the input buffer 277207753Smm * \param out Beginning of the output buffer 278207753Smm * \param out_pos The next byte will be written to out[*out_pos]. 279207753Smm * *out_pos is updated only if encoding succeeds. 280207753Smm * \param out_size Size of the out buffer; the first byte into 281207753Smm * which no data is written to is out[out_size]. 282207753Smm * 283207753Smm * \return - LZMA_OK: Encoding was successful. 284207753Smm * - LZMA_BUF_ERROR: Not enough output buffer space. 285223935Smm * - LZMA_UNSUPPORTED_CHECK 286207753Smm * - LZMA_OPTIONS_ERROR 287207753Smm * - LZMA_MEM_ERROR 288207753Smm * - LZMA_DATA_ERROR 289207753Smm * - LZMA_PROG_ERROR 290207753Smm */ 291207753Smmextern LZMA_API(lzma_ret) lzma_easy_buffer_encode( 292207753Smm uint32_t preset, lzma_check check, 293278433Srpaulo const lzma_allocator *allocator, 294278433Srpaulo const uint8_t *in, size_t in_size, 295207753Smm uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; 296207753Smm 297207753Smm 298207753Smm/** 299207753Smm * \brief Initialize .xz Stream encoder using a custom filter chain 300207753Smm * 301207753Smm * \param strm Pointer to properly prepared lzma_stream 302207753Smm * \param filters Array of filters. This must be terminated with 303207753Smm * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for 304207753Smm * more information. 305207753Smm * \param check Type of the integrity check to calculate from 306207753Smm * uncompressed data. 307207753Smm * 308207753Smm * \return - LZMA_OK: Initialization was successful. 309207753Smm * - LZMA_MEM_ERROR 310223935Smm * - LZMA_UNSUPPORTED_CHECK 311207753Smm * - LZMA_OPTIONS_ERROR 312207753Smm * - LZMA_PROG_ERROR 313207753Smm */ 314207753Smmextern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, 315207753Smm const lzma_filter *filters, lzma_check check) 316207753Smm lzma_nothrow lzma_attr_warn_unused_result; 317207753Smm 318207753Smm 319207753Smm/** 320278433Srpaulo * \brief Calculate approximate memory usage of multithreaded .xz encoder 321278433Srpaulo * 322278433Srpaulo * Since doing the encoding in threaded mode doesn't affect the memory 323278433Srpaulo * requirements of single-threaded decompressor, you can use 324278433Srpaulo * lzma_easy_decoder_memusage(options->preset) or 325278433Srpaulo * lzma_raw_decoder_memusage(options->filters) to calculate 326278433Srpaulo * the decompressor memory requirements. 327278433Srpaulo * 328278433Srpaulo * \param options Compression options 329278433Srpaulo * 330278433Srpaulo * \return Number of bytes of memory required for encoding with the 331278433Srpaulo * given options. If an error occurs, for example due to 332278433Srpaulo * unsupported preset or filter chain, UINT64_MAX is returned. 333278433Srpaulo */ 334278433Srpauloextern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( 335278433Srpaulo const lzma_mt *options) lzma_nothrow lzma_attr_pure; 336278433Srpaulo 337278433Srpaulo 338278433Srpaulo/** 339278433Srpaulo * \brief Initialize multithreaded .xz Stream encoder 340278433Srpaulo * 341278433Srpaulo * This provides the functionality of lzma_easy_encoder() and 342278433Srpaulo * lzma_stream_encoder() as a single function for multithreaded use. 343278433Srpaulo * 344278433Srpaulo * The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH, 345278433Srpaulo * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be 346278433Srpaulo * added in the future. 347278433Srpaulo * 348278433Srpaulo * \param strm Pointer to properly prepared lzma_stream 349278433Srpaulo * \param options Pointer to multithreaded compression options 350278433Srpaulo * 351278433Srpaulo * \return - LZMA_OK 352278433Srpaulo * - LZMA_MEM_ERROR 353278433Srpaulo * - LZMA_UNSUPPORTED_CHECK 354278433Srpaulo * - LZMA_OPTIONS_ERROR 355278433Srpaulo * - LZMA_PROG_ERROR 356278433Srpaulo */ 357278433Srpauloextern LZMA_API(lzma_ret) lzma_stream_encoder_mt( 358278433Srpaulo lzma_stream *strm, const lzma_mt *options) 359278433Srpaulo lzma_nothrow lzma_attr_warn_unused_result; 360278433Srpaulo 361278433Srpaulo 362278433Srpaulo/** 363207753Smm * \brief Initialize .lzma encoder (legacy file format) 364207753Smm * 365207753Smm * The .lzma format is sometimes called the LZMA_Alone format, which is the 366207753Smm * reason for the name of this function. The .lzma format supports only the 367207753Smm * LZMA1 filter. There is no support for integrity checks like CRC32. 368207753Smm * 369207753Smm * Use this function if and only if you need to create files readable by 370207753Smm * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format 371207753Smm * is strongly recommended. 372207753Smm * 373207753Smm * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH. 374207753Smm * No kind of flushing is supported, because the file format doesn't make 375207753Smm * it possible. 376207753Smm * 377207753Smm * \return - LZMA_OK 378207753Smm * - LZMA_MEM_ERROR 379207753Smm * - LZMA_OPTIONS_ERROR 380207753Smm * - LZMA_PROG_ERROR 381207753Smm */ 382207753Smmextern LZMA_API(lzma_ret) lzma_alone_encoder( 383207753Smm lzma_stream *strm, const lzma_options_lzma *options) 384207753Smm lzma_nothrow lzma_attr_warn_unused_result; 385207753Smm 386207753Smm 387207753Smm/** 388207753Smm * \brief Calculate output buffer size for single-call Stream encoder 389207753Smm * 390207753Smm * When trying to compress uncompressible data, the encoded size will be 391207753Smm * slightly bigger than the input data. This function calculates how much 392207753Smm * output buffer space is required to be sure that lzma_stream_buffer_encode() 393207753Smm * doesn't return LZMA_BUF_ERROR. 394207753Smm * 395207753Smm * The calculated value is not exact, but it is guaranteed to be big enough. 396207753Smm * The actual maximum output space required may be slightly smaller (up to 397207753Smm * about 100 bytes). This should not be a problem in practice. 398207753Smm * 399207753Smm * If the calculated maximum size doesn't fit into size_t or would make the 400207753Smm * Stream grow past LZMA_VLI_MAX (which should never happen in practice), 401207753Smm * zero is returned to indicate the error. 402207753Smm * 403207753Smm * \note The limit calculated by this function applies only to 404207753Smm * single-call encoding. Multi-call encoding may (and probably 405207753Smm * will) have larger maximum expansion when encoding 406207753Smm * uncompressible data. Currently there is no function to 407207753Smm * calculate the maximum expansion of multi-call encoding. 408207753Smm */ 409207753Smmextern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) 410207753Smm lzma_nothrow; 411207753Smm 412207753Smm 413207753Smm/** 414207753Smm * \brief Single-call .xz Stream encoder 415207753Smm * 416207753Smm * \param filters Array of filters. This must be terminated with 417207753Smm * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h 418207753Smm * for more information. 419207753Smm * \param check Type of the integrity check to calculate from 420207753Smm * uncompressed data. 421207753Smm * \param allocator lzma_allocator for custom allocator functions. 422207753Smm * Set to NULL to use malloc() and free(). 423207753Smm * \param in Beginning of the input buffer 424207753Smm * \param in_size Size of the input buffer 425207753Smm * \param out Beginning of the output buffer 426207753Smm * \param out_pos The next byte will be written to out[*out_pos]. 427207753Smm * *out_pos is updated only if encoding succeeds. 428207753Smm * \param out_size Size of the out buffer; the first byte into 429207753Smm * which no data is written to is out[out_size]. 430207753Smm * 431207753Smm * \return - LZMA_OK: Encoding was successful. 432207753Smm * - LZMA_BUF_ERROR: Not enough output buffer space. 433223935Smm * - LZMA_UNSUPPORTED_CHECK 434207753Smm * - LZMA_OPTIONS_ERROR 435207753Smm * - LZMA_MEM_ERROR 436207753Smm * - LZMA_DATA_ERROR 437207753Smm * - LZMA_PROG_ERROR 438207753Smm */ 439207753Smmextern LZMA_API(lzma_ret) lzma_stream_buffer_encode( 440207753Smm lzma_filter *filters, lzma_check check, 441278433Srpaulo const lzma_allocator *allocator, 442278433Srpaulo const uint8_t *in, size_t in_size, 443207753Smm uint8_t *out, size_t *out_pos, size_t out_size) 444207753Smm lzma_nothrow lzma_attr_warn_unused_result; 445207753Smm 446207753Smm 447207753Smm/************ 448207753Smm * Decoding * 449207753Smm ************/ 450207753Smm 451207753Smm/** 452207753Smm * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream 453207753Smm * being decoded has no integrity check. Note that when used with 454207753Smm * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK 455207753Smm * if LZMA_TELL_NO_CHECK is used. 456207753Smm */ 457207753Smm#define LZMA_TELL_NO_CHECK UINT32_C(0x01) 458207753Smm 459207753Smm 460207753Smm/** 461207753Smm * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input 462207753Smm * stream has an integrity check, but the type of the integrity check is not 463207753Smm * supported by this liblzma version or build. Such files can still be 464207753Smm * decoded, but the integrity check cannot be verified. 465207753Smm */ 466207753Smm#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02) 467207753Smm 468207753Smm 469207753Smm/** 470207753Smm * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type 471207753Smm * of the integrity check is known. The type can then be got with 472207753Smm * lzma_get_check(). 473207753Smm */ 474207753Smm#define LZMA_TELL_ANY_CHECK UINT32_C(0x04) 475207753Smm 476207753Smm 477207753Smm/** 478278433Srpaulo * This flag makes lzma_code() not calculate and verify the integrity check 479278433Srpaulo * of the compressed data in .xz files. This means that invalid integrity 480278433Srpaulo * check values won't be detected and LZMA_DATA_ERROR won't be returned in 481278433Srpaulo * such cases. 482278433Srpaulo * 483278433Srpaulo * This flag only affects the checks of the compressed data itself; the CRC32 484278433Srpaulo * values in the .xz headers will still be verified normally. 485278433Srpaulo * 486278433Srpaulo * Don't use this flag unless you know what you are doing. Possible reasons 487278433Srpaulo * to use this flag: 488278433Srpaulo * 489278433Srpaulo * - Trying to recover data from a corrupt .xz file. 490278433Srpaulo * 491278433Srpaulo * - Speeding up decompression, which matters mostly with SHA-256 492278433Srpaulo * or with files that have compressed extremely well. It's recommended 493278433Srpaulo * to not use this flag for this purpose unless the file integrity is 494278433Srpaulo * verified externally in some other way. 495278433Srpaulo * 496278433Srpaulo * Support for this flag was added in liblzma 5.1.4beta. 497278433Srpaulo */ 498278433Srpaulo#define LZMA_IGNORE_CHECK UINT32_C(0x10) 499278433Srpaulo 500278433Srpaulo 501278433Srpaulo/** 502207753Smm * This flag enables decoding of concatenated files with file formats that 503207753Smm * allow concatenating compressed files as is. From the formats currently 504207753Smm * supported by liblzma, only the .xz format allows concatenated files. 505207753Smm * Concatenated files are not allowed with the legacy .lzma format. 506207753Smm * 507207753Smm * This flag also affects the usage of the `action' argument for lzma_code(). 508207753Smm * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END 509207753Smm * unless LZMA_FINISH is used as `action'. Thus, the application has to set 510207753Smm * LZMA_FINISH in the same way as it does when encoding. 511207753Smm * 512207753Smm * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH 513207753Smm * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required. 514207753Smm */ 515207753Smm#define LZMA_CONCATENATED UINT32_C(0x08) 516207753Smm 517207753Smm 518207753Smm/** 519207753Smm * \brief Initialize .xz Stream decoder 520207753Smm * 521207753Smm * \param strm Pointer to properly prepared lzma_stream 522215187Smm * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 523334607Sdelphij * to effectively disable the limiter. liblzma 524334607Sdelphij * 5.2.3 and earlier don't allow 0 here and return 525334607Sdelphij * LZMA_PROG_ERROR; later versions treat 0 as if 1 526334607Sdelphij * had been specified. 527207753Smm * \param flags Bitwise-or of zero or more of the decoder flags: 528207753Smm * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 529207753Smm * LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED 530207753Smm * 531207753Smm * \return - LZMA_OK: Initialization was successful. 532207753Smm * - LZMA_MEM_ERROR: Cannot allocate memory. 533207753Smm * - LZMA_OPTIONS_ERROR: Unsupported flags 534215187Smm * - LZMA_PROG_ERROR 535207753Smm */ 536207753Smmextern LZMA_API(lzma_ret) lzma_stream_decoder( 537207753Smm lzma_stream *strm, uint64_t memlimit, uint32_t flags) 538207753Smm lzma_nothrow lzma_attr_warn_unused_result; 539207753Smm 540207753Smm 541207753Smm/** 542207753Smm * \brief Decode .xz Streams and .lzma files with autodetection 543207753Smm * 544207753Smm * This decoder autodetects between the .xz and .lzma file formats, and 545207753Smm * calls lzma_stream_decoder() or lzma_alone_decoder() once the type 546207753Smm * of the input file has been detected. 547207753Smm * 548207753Smm * \param strm Pointer to properly prepared lzma_stream 549215187Smm * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 550334607Sdelphij * to effectively disable the limiter. liblzma 551334607Sdelphij * 5.2.3 and earlier don't allow 0 here and return 552334607Sdelphij * LZMA_PROG_ERROR; later versions treat 0 as if 1 553334607Sdelphij * had been specified. 554207753Smm * \param flags Bitwise-or of flags, or zero for no flags. 555207753Smm * 556207753Smm * \return - LZMA_OK: Initialization was successful. 557207753Smm * - LZMA_MEM_ERROR: Cannot allocate memory. 558207753Smm * - LZMA_OPTIONS_ERROR: Unsupported flags 559215187Smm * - LZMA_PROG_ERROR 560207753Smm */ 561207753Smmextern LZMA_API(lzma_ret) lzma_auto_decoder( 562207753Smm lzma_stream *strm, uint64_t memlimit, uint32_t flags) 563207753Smm lzma_nothrow lzma_attr_warn_unused_result; 564207753Smm 565207753Smm 566207753Smm/** 567207753Smm * \brief Initialize .lzma decoder (legacy file format) 568207753Smm * 569334607Sdelphij * \param strm Pointer to properly prepared lzma_stream 570334607Sdelphij * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 571334607Sdelphij * to effectively disable the limiter. liblzma 572334607Sdelphij * 5.2.3 and earlier don't allow 0 here and return 573334607Sdelphij * LZMA_PROG_ERROR; later versions treat 0 as if 1 574334607Sdelphij * had been specified. 575334607Sdelphij * 576207753Smm * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. 577334607Sdelphij * There is no need to use LZMA_FINISH, but it's allowed because it may 578334607Sdelphij * simplify certain types of applications. 579207753Smm * 580207753Smm * \return - LZMA_OK 581207753Smm * - LZMA_MEM_ERROR 582215187Smm * - LZMA_PROG_ERROR 583207753Smm */ 584207753Smmextern LZMA_API(lzma_ret) lzma_alone_decoder( 585207753Smm lzma_stream *strm, uint64_t memlimit) 586207753Smm lzma_nothrow lzma_attr_warn_unused_result; 587207753Smm 588207753Smm 589207753Smm/** 590207753Smm * \brief Single-call .xz Stream decoder 591207753Smm * 592207753Smm * \param memlimit Pointer to how much memory the decoder is allowed 593207753Smm * to allocate. The value pointed by this pointer is 594207753Smm * modified if and only if LZMA_MEMLIMIT_ERROR is 595207753Smm * returned. 596207753Smm * \param flags Bitwise-or of zero or more of the decoder flags: 597207753Smm * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 598207753Smm * LZMA_CONCATENATED. Note that LZMA_TELL_ANY_CHECK 599207753Smm * is not allowed and will return LZMA_PROG_ERROR. 600207753Smm * \param allocator lzma_allocator for custom allocator functions. 601207753Smm * Set to NULL to use malloc() and free(). 602207753Smm * \param in Beginning of the input buffer 603207753Smm * \param in_pos The next byte will be read from in[*in_pos]. 604207753Smm * *in_pos is updated only if decoding succeeds. 605207753Smm * \param in_size Size of the input buffer; the first byte that 606207753Smm * won't be read is in[in_size]. 607207753Smm * \param out Beginning of the output buffer 608207753Smm * \param out_pos The next byte will be written to out[*out_pos]. 609215187Smm * *out_pos is updated only if decoding succeeds. 610207753Smm * \param out_size Size of the out buffer; the first byte into 611207753Smm * which no data is written to is out[out_size]. 612207753Smm * 613207753Smm * \return - LZMA_OK: Decoding was successful. 614207753Smm * - LZMA_FORMAT_ERROR 615207753Smm * - LZMA_OPTIONS_ERROR 616207753Smm * - LZMA_DATA_ERROR 617207753Smm * - LZMA_NO_CHECK: This can be returned only if using 618207753Smm * the LZMA_TELL_NO_CHECK flag. 619207753Smm * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using 620207753Smm * the LZMA_TELL_UNSUPPORTED_CHECK flag. 621207753Smm * - LZMA_MEM_ERROR 622207753Smm * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 623207753Smm * The minimum required memlimit value was stored to *memlimit. 624207753Smm * - LZMA_BUF_ERROR: Output buffer was too small. 625207753Smm * - LZMA_PROG_ERROR 626207753Smm */ 627207753Smmextern LZMA_API(lzma_ret) lzma_stream_buffer_decode( 628278433Srpaulo uint64_t *memlimit, uint32_t flags, 629278433Srpaulo const lzma_allocator *allocator, 630207753Smm const uint8_t *in, size_t *in_pos, size_t in_size, 631207753Smm uint8_t *out, size_t *out_pos, size_t out_size) 632207753Smm lzma_nothrow lzma_attr_warn_unused_result; 633