|
||||
File indexing completed on 2024-11-15 09:44:23
0001 /** 0002 * \file lzma/container.h 0003 * \brief File formats 0004 * \note Never include this file directly. Use <lzma.h> instead. 0005 */ 0006 0007 /* 0008 * Author: Lasse Collin 0009 * 0010 * This file has been put into the public domain. 0011 * You can do whatever you want with this file. 0012 */ 0013 0014 #ifndef LZMA_H_INTERNAL 0015 # error Never include this file directly. Use <lzma.h> instead. 0016 #endif 0017 0018 0019 /************ 0020 * Encoding * 0021 ************/ 0022 0023 /** 0024 * \brief Default compression preset 0025 * 0026 * It's not straightforward to recommend a default preset, because in some 0027 * cases keeping the resource usage relatively low is more important that 0028 * getting the maximum compression ratio. 0029 */ 0030 #define LZMA_PRESET_DEFAULT UINT32_C(6) 0031 0032 0033 /** 0034 * \brief Mask for preset level 0035 * 0036 * This is useful only if you need to extract the level from the preset 0037 * variable. That should be rare. 0038 */ 0039 #define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) 0040 0041 0042 /* 0043 * Preset flags 0044 * 0045 * Currently only one flag is defined. 0046 */ 0047 0048 /** 0049 * \brief Extreme compression preset 0050 * 0051 * This flag modifies the preset to make the encoding significantly slower 0052 * while improving the compression ratio only marginally. This is useful 0053 * when you don't mind spending time to get as small result as possible. 0054 * 0055 * This flag doesn't affect the memory usage requirements of the decoder (at 0056 * least not significantly). The memory usage of the encoder may be increased 0057 * a little but only at the lowest preset levels (0-3). 0058 */ 0059 #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) 0060 0061 0062 /** 0063 * \brief Multithreading options 0064 */ 0065 typedef struct { 0066 /** 0067 * \brief Flags 0068 * 0069 * Set this to zero if no flags are wanted. 0070 * 0071 * Encoder: No flags are currently supported. 0072 * 0073 * Decoder: Bitwise-or of zero or more of the decoder flags: 0074 * - LZMA_TELL_NO_CHECK 0075 * - LZMA_TELL_UNSUPPORTED_CHECK 0076 * - LZMA_TELL_ANY_CHECK 0077 * - LZMA_IGNORE_CHECK 0078 * - LZMA_CONCATENATED 0079 * - LZMA_FAIL_FAST 0080 */ 0081 uint32_t flags; 0082 0083 /** 0084 * \brief Number of worker threads to use 0085 */ 0086 uint32_t threads; 0087 0088 /** 0089 * \brief Encoder only: Maximum uncompressed size of a Block 0090 * 0091 * The encoder will start a new .xz Block every block_size bytes. 0092 * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code() 0093 * the caller may tell liblzma to start a new Block earlier. 0094 * 0095 * With LZMA2, a recommended block size is 2-4 times the LZMA2 0096 * dictionary size. With very small dictionaries, it is recommended 0097 * to use at least 1 MiB block size for good compression ratio, even 0098 * if this is more than four times the dictionary size. Note that 0099 * these are only recommendations for typical use cases; feel free 0100 * to use other values. Just keep in mind that using a block size 0101 * less than the LZMA2 dictionary size is waste of RAM. 0102 * 0103 * Set this to 0 to let liblzma choose the block size depending 0104 * on the compression options. For LZMA2 it will be 3*dict_size 0105 * or 1 MiB, whichever is more. 0106 * 0107 * For each thread, about 3 * block_size bytes of memory will be 0108 * allocated. This may change in later liblzma versions. If so, 0109 * the memory usage will probably be reduced, not increased. 0110 */ 0111 uint64_t block_size; 0112 0113 /** 0114 * \brief Timeout to allow lzma_code() to return early 0115 * 0116 * Multithreading can make liblzma consume input and produce 0117 * output in a very bursty way: it may first read a lot of input 0118 * to fill internal buffers, then no input or output occurs for 0119 * a while. 0120 * 0121 * In single-threaded mode, lzma_code() won't return until it has 0122 * either consumed all the input or filled the output buffer. If 0123 * this is done in multithreaded mode, it may cause a call 0124 * lzma_code() to take even tens of seconds, which isn't acceptable 0125 * in all applications. 0126 * 0127 * To avoid very long blocking times in lzma_code(), a timeout 0128 * (in milliseconds) may be set here. If lzma_code() would block 0129 * longer than this number of milliseconds, it will return with 0130 * LZMA_OK. Reasonable values are 100 ms or more. The xz command 0131 * line tool uses 300 ms. 0132 * 0133 * If long blocking times are acceptable, set timeout to a special 0134 * value of 0. This will disable the timeout mechanism and will make 0135 * lzma_code() block until all the input is consumed or the output 0136 * buffer has been filled. 0137 * 0138 * \note Even with a timeout, lzma_code() might sometimes take 0139 * a long time to return. No timing guarantees are made. 0140 */ 0141 uint32_t timeout; 0142 0143 /** 0144 * \brief Encoder only: Compression preset 0145 * 0146 * The preset is set just like with lzma_easy_encoder(). 0147 * The preset is ignored if filters below is non-NULL. 0148 */ 0149 uint32_t preset; 0150 0151 /** 0152 * \brief Encoder only: Filter chain (alternative to a preset) 0153 * 0154 * If this is NULL, the preset above is used. Otherwise the preset 0155 * is ignored and the filter chain specified here is used. 0156 */ 0157 const lzma_filter *filters; 0158 0159 /** 0160 * \brief Encoder only: Integrity check type 0161 * 0162 * See check.h for available checks. The xz command line tool 0163 * defaults to LZMA_CHECK_CRC64, which is a good choice if you 0164 * are unsure. 0165 */ 0166 lzma_check check; 0167 0168 /* 0169 * Reserved space to allow possible future extensions without 0170 * breaking the ABI. You should not touch these, because the names 0171 * of these variables may change. These are and will never be used 0172 * with the currently supported options, so it is safe to leave these 0173 * uninitialized. 0174 */ 0175 /** \private Reserved member. */ 0176 lzma_reserved_enum reserved_enum1; 0177 0178 /** \private Reserved member. */ 0179 lzma_reserved_enum reserved_enum2; 0180 0181 /** \private Reserved member. */ 0182 lzma_reserved_enum reserved_enum3; 0183 0184 /** \private Reserved member. */ 0185 uint32_t reserved_int1; 0186 0187 /** \private Reserved member. */ 0188 uint32_t reserved_int2; 0189 0190 /** \private Reserved member. */ 0191 uint32_t reserved_int3; 0192 0193 /** \private Reserved member. */ 0194 uint32_t reserved_int4; 0195 0196 /** 0197 * \brief Memory usage limit to reduce the number of threads 0198 * 0199 * Encoder: Ignored. 0200 * 0201 * Decoder: 0202 * 0203 * If the number of threads has been set so high that more than 0204 * memlimit_threading bytes of memory would be needed, the number 0205 * of threads will be reduced so that the memory usage will not exceed 0206 * memlimit_threading bytes. However, if memlimit_threading cannot 0207 * be met even in single-threaded mode, then decoding will continue 0208 * in single-threaded mode and memlimit_threading may be exceeded 0209 * even by a large amount. That is, memlimit_threading will never make 0210 * lzma_code() return LZMA_MEMLIMIT_ERROR. To truly cap the memory 0211 * usage, see memlimit_stop below. 0212 * 0213 * Setting memlimit_threading to UINT64_MAX or a similar huge value 0214 * means that liblzma is allowed to keep the whole compressed file 0215 * and the whole uncompressed file in memory in addition to the memory 0216 * needed by the decompressor data structures used by each thread! 0217 * In other words, a reasonable value limit must be set here or it 0218 * will cause problems sooner or later. If you have no idea what 0219 * a reasonable value could be, try lzma_physmem() / 4 as a starting 0220 * point. Setting this limit will never prevent decompression of 0221 * a file; this will only reduce the number of threads. 0222 * 0223 * If memlimit_threading is greater than memlimit_stop, then the value 0224 * of memlimit_stop will be used for both. 0225 */ 0226 uint64_t memlimit_threading; 0227 0228 /** 0229 * \brief Memory usage limit that should never be exceeded 0230 * 0231 * Encoder: Ignored. 0232 * 0233 * Decoder: If decompressing will need more than this amount of 0234 * memory even in the single-threaded mode, then lzma_code() will 0235 * return LZMA_MEMLIMIT_ERROR. 0236 */ 0237 uint64_t memlimit_stop; 0238 0239 /** \private Reserved member. */ 0240 uint64_t reserved_int7; 0241 0242 /** \private Reserved member. */ 0243 uint64_t reserved_int8; 0244 0245 /** \private Reserved member. */ 0246 void *reserved_ptr1; 0247 0248 /** \private Reserved member. */ 0249 void *reserved_ptr2; 0250 0251 /** \private Reserved member. */ 0252 void *reserved_ptr3; 0253 0254 /** \private Reserved member. */ 0255 void *reserved_ptr4; 0256 0257 } lzma_mt; 0258 0259 0260 /** 0261 * \brief Calculate approximate memory usage of easy encoder 0262 * 0263 * This function is a wrapper for lzma_raw_encoder_memusage(). 0264 * 0265 * \param preset Compression preset (level and possible flags) 0266 * 0267 * \return Number of bytes of memory required for the given 0268 * preset when encoding or UINT64_MAX on error. 0269 */ 0270 extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) 0271 lzma_nothrow lzma_attr_pure; 0272 0273 0274 /** 0275 * \brief Calculate approximate decoder memory usage of a preset 0276 * 0277 * This function is a wrapper for lzma_raw_decoder_memusage(). 0278 * 0279 * \param preset Compression preset (level and possible flags) 0280 * 0281 * \return Number of bytes of memory required to decompress a file 0282 * that was compressed using the given preset or UINT64_MAX 0283 * on error. 0284 */ 0285 extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) 0286 lzma_nothrow lzma_attr_pure; 0287 0288 0289 /** 0290 * \brief Initialize .xz Stream encoder using a preset number 0291 * 0292 * This function is intended for those who just want to use the basic features 0293 * of liblzma (that is, most developers out there). 0294 * 0295 * If initialization fails (return value is not LZMA_OK), all the memory 0296 * allocated for *strm by liblzma is always freed. Thus, there is no need 0297 * to call lzma_end() after failed initialization. 0298 * 0299 * If initialization succeeds, use lzma_code() to do the actual encoding. 0300 * Valid values for `action' (the second argument of lzma_code()) are 0301 * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, 0302 * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH. 0303 * 0304 * \param strm Pointer to lzma_stream that is at least initialized 0305 * with LZMA_STREAM_INIT. 0306 * \param preset Compression preset to use. A preset consist of level 0307 * number and zero or more flags. Usually flags aren't 0308 * used, so preset is simply a number [0, 9] which match 0309 * the options -0 ... -9 of the xz command line tool. 0310 * Additional flags can be be set using bitwise-or with 0311 * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME. 0312 * \param check Integrity check type to use. See check.h for available 0313 * checks. The xz command line tool defaults to 0314 * LZMA_CHECK_CRC64, which is a good choice if you are 0315 * unsure. LZMA_CHECK_CRC32 is good too as long as the 0316 * uncompressed file is not many gigabytes. 0317 * 0318 * \return Possible lzma_ret values: 0319 * - LZMA_OK: Initialization succeeded. Use lzma_code() to 0320 * encode your data. 0321 * - LZMA_MEM_ERROR: Memory allocation failed. 0322 * - LZMA_OPTIONS_ERROR: The given compression preset is not 0323 * supported by this build of liblzma. 0324 * - LZMA_UNSUPPORTED_CHECK: The given check type is not 0325 * supported by this liblzma build. 0326 * - LZMA_PROG_ERROR: One or more of the parameters have values 0327 * that will never be valid. For example, strm == NULL. 0328 */ 0329 extern LZMA_API(lzma_ret) lzma_easy_encoder( 0330 lzma_stream *strm, uint32_t preset, lzma_check check) 0331 lzma_nothrow lzma_attr_warn_unused_result; 0332 0333 0334 /** 0335 * \brief Single-call .xz Stream encoding using a preset number 0336 * 0337 * The maximum required output buffer size can be calculated with 0338 * lzma_stream_buffer_bound(). 0339 * 0340 * \param preset Compression preset to use. See the description 0341 * in lzma_easy_encoder(). 0342 * \param check Type of the integrity check to calculate from 0343 * uncompressed data. 0344 * \param allocator lzma_allocator for custom allocator functions. 0345 * Set to NULL to use malloc() and free(). 0346 * \param in Beginning of the input buffer 0347 * \param in_size Size of the input buffer 0348 * \param[out] out Beginning of the output buffer 0349 * \param[out] out_pos The next byte will be written to out[*out_pos]. 0350 * *out_pos is updated only if encoding succeeds. 0351 * \param out_size Size of the out buffer; the first byte into 0352 * which no data is written to is out[out_size]. 0353 * 0354 * \return Possible lzma_ret values: 0355 * - LZMA_OK: Encoding was successful. 0356 * - LZMA_BUF_ERROR: Not enough output buffer space. 0357 * - LZMA_UNSUPPORTED_CHECK 0358 * - LZMA_OPTIONS_ERROR 0359 * - LZMA_MEM_ERROR 0360 * - LZMA_DATA_ERROR 0361 * - LZMA_PROG_ERROR 0362 */ 0363 extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( 0364 uint32_t preset, lzma_check check, 0365 const lzma_allocator *allocator, 0366 const uint8_t *in, size_t in_size, 0367 uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; 0368 0369 0370 /** 0371 * \brief Initialize .xz Stream encoder using a custom filter chain 0372 * 0373 * \param strm Pointer to lzma_stream that is at least initialized 0374 * with LZMA_STREAM_INIT. 0375 * \param filters Array of filters terminated with 0376 * .id == LZMA_VLI_UNKNOWN. See filters.h for more 0377 * information. 0378 * \param check Type of the integrity check to calculate from 0379 * uncompressed data. 0380 * 0381 * \return Possible lzma_ret values: 0382 * - LZMA_OK: Initialization was successful. 0383 * - LZMA_MEM_ERROR 0384 * - LZMA_UNSUPPORTED_CHECK 0385 * - LZMA_OPTIONS_ERROR 0386 * - LZMA_PROG_ERROR 0387 */ 0388 extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, 0389 const lzma_filter *filters, lzma_check check) 0390 lzma_nothrow lzma_attr_warn_unused_result; 0391 0392 0393 /** 0394 * \brief Calculate approximate memory usage of multithreaded .xz encoder 0395 * 0396 * Since doing the encoding in threaded mode doesn't affect the memory 0397 * requirements of single-threaded decompressor, you can use 0398 * lzma_easy_decoder_memusage(options->preset) or 0399 * lzma_raw_decoder_memusage(options->filters) to calculate 0400 * the decompressor memory requirements. 0401 * 0402 * \param options Compression options 0403 * 0404 * \return Number of bytes of memory required for encoding with the 0405 * given options. If an error occurs, for example due to 0406 * unsupported preset or filter chain, UINT64_MAX is returned. 0407 */ 0408 extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( 0409 const lzma_mt *options) lzma_nothrow lzma_attr_pure; 0410 0411 0412 /** 0413 * \brief Initialize multithreaded .xz Stream encoder 0414 * 0415 * This provides the functionality of lzma_easy_encoder() and 0416 * lzma_stream_encoder() as a single function for multithreaded use. 0417 * 0418 * The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH, 0419 * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be 0420 * added in the future. 0421 * 0422 * \param strm Pointer to lzma_stream that is at least initialized 0423 * with LZMA_STREAM_INIT. 0424 * \param options Pointer to multithreaded compression options 0425 * 0426 * \return Possible lzma_ret values: 0427 * - LZMA_OK 0428 * - LZMA_MEM_ERROR 0429 * - LZMA_UNSUPPORTED_CHECK 0430 * - LZMA_OPTIONS_ERROR 0431 * - LZMA_PROG_ERROR 0432 */ 0433 extern LZMA_API(lzma_ret) lzma_stream_encoder_mt( 0434 lzma_stream *strm, const lzma_mt *options) 0435 lzma_nothrow lzma_attr_warn_unused_result; 0436 0437 0438 /** 0439 * \brief Initialize .lzma encoder (legacy file format) 0440 * 0441 * The .lzma format is sometimes called the LZMA_Alone format, which is the 0442 * reason for the name of this function. The .lzma format supports only the 0443 * LZMA1 filter. There is no support for integrity checks like CRC32. 0444 * 0445 * Use this function if and only if you need to create files readable by 0446 * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format 0447 * is strongly recommended. 0448 * 0449 * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH. 0450 * No kind of flushing is supported, because the file format doesn't make 0451 * it possible. 0452 * 0453 * \param strm Pointer to lzma_stream that is at least initialized 0454 * with LZMA_STREAM_INIT. 0455 * \param options Pointer to encoder options 0456 * 0457 * \return Possible lzma_ret values: 0458 * - LZMA_OK 0459 * - LZMA_MEM_ERROR 0460 * - LZMA_OPTIONS_ERROR 0461 * - LZMA_PROG_ERROR 0462 */ 0463 extern LZMA_API(lzma_ret) lzma_alone_encoder( 0464 lzma_stream *strm, const lzma_options_lzma *options) 0465 lzma_nothrow lzma_attr_warn_unused_result; 0466 0467 0468 /** 0469 * \brief Calculate output buffer size for single-call Stream encoder 0470 * 0471 * When trying to compress incompressible data, the encoded size will be 0472 * slightly bigger than the input data. This function calculates how much 0473 * output buffer space is required to be sure that lzma_stream_buffer_encode() 0474 * doesn't return LZMA_BUF_ERROR. 0475 * 0476 * The calculated value is not exact, but it is guaranteed to be big enough. 0477 * The actual maximum output space required may be slightly smaller (up to 0478 * about 100 bytes). This should not be a problem in practice. 0479 * 0480 * If the calculated maximum size doesn't fit into size_t or would make the 0481 * Stream grow past LZMA_VLI_MAX (which should never happen in practice), 0482 * zero is returned to indicate the error. 0483 * 0484 * \note The limit calculated by this function applies only to 0485 * single-call encoding. Multi-call encoding may (and probably 0486 * will) have larger maximum expansion when encoding 0487 * incompressible data. Currently there is no function to 0488 * calculate the maximum expansion of multi-call encoding. 0489 * 0490 * \param uncompressed_size Size in bytes of the uncompressed 0491 * input data 0492 * 0493 * \return Maximum number of bytes needed to store the compressed data. 0494 */ 0495 extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) 0496 lzma_nothrow; 0497 0498 0499 /** 0500 * \brief Single-call .xz Stream encoder 0501 * 0502 * \param filters Array of filters terminated with 0503 * .id == LZMA_VLI_UNKNOWN. See filters.h for more 0504 * information. 0505 * \param check Type of the integrity check to calculate from 0506 * uncompressed data. 0507 * \param allocator lzma_allocator for custom allocator functions. 0508 * Set to NULL to use malloc() and free(). 0509 * \param in Beginning of the input buffer 0510 * \param in_size Size of the input buffer 0511 * \param[out] out Beginning of the output buffer 0512 * \param[out] out_pos The next byte will be written to out[*out_pos]. 0513 * *out_pos is updated only if encoding succeeds. 0514 * \param out_size Size of the out buffer; the first byte into 0515 * which no data is written to is out[out_size]. 0516 * 0517 * \return Possible lzma_ret values: 0518 * - LZMA_OK: Encoding was successful. 0519 * - LZMA_BUF_ERROR: Not enough output buffer space. 0520 * - LZMA_UNSUPPORTED_CHECK 0521 * - LZMA_OPTIONS_ERROR 0522 * - LZMA_MEM_ERROR 0523 * - LZMA_DATA_ERROR 0524 * - LZMA_PROG_ERROR 0525 */ 0526 extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( 0527 lzma_filter *filters, lzma_check check, 0528 const lzma_allocator *allocator, 0529 const uint8_t *in, size_t in_size, 0530 uint8_t *out, size_t *out_pos, size_t out_size) 0531 lzma_nothrow lzma_attr_warn_unused_result; 0532 0533 0534 /** 0535 * \brief MicroLZMA encoder 0536 * 0537 * The MicroLZMA format is a raw LZMA stream whose first byte (always 0x00) 0538 * has been replaced with bitwise-negation of the LZMA properties (lc/lp/pb). 0539 * This encoding ensures that the first byte of MicroLZMA stream is never 0540 * 0x00. There is no end of payload marker and thus the uncompressed size 0541 * must be stored separately. For the best error detection the dictionary 0542 * size should be stored separately as well but alternatively one may use 0543 * the uncompressed size as the dictionary size when decoding. 0544 * 0545 * With the MicroLZMA encoder, lzma_code() behaves slightly unusually. 0546 * The action argument must be LZMA_FINISH and the return value will never be 0547 * LZMA_OK. Thus the encoding is always done with a single lzma_code() after 0548 * the initialization. The benefit of the combination of initialization 0549 * function and lzma_code() is that memory allocations can be re-used for 0550 * better performance. 0551 * 0552 * lzma_code() will try to encode as much input as is possible to fit into 0553 * the given output buffer. If not all input can be encoded, the stream will 0554 * be finished without encoding all the input. The caller must check both 0555 * input and output buffer usage after lzma_code() (total_in and total_out 0556 * in lzma_stream can be convenient). Often lzma_code() can fill the output 0557 * buffer completely if there is a lot of input, but sometimes a few bytes 0558 * may remain unused because the next LZMA symbol would require more space. 0559 * 0560 * lzma_stream.avail_out must be at least 6. Otherwise LZMA_PROG_ERROR 0561 * will be returned. 0562 * 0563 * The LZMA dictionary should be reasonably low to speed up the encoder 0564 * re-initialization. A good value is bigger than the resulting 0565 * uncompressed size of most of the output chunks. For example, if output 0566 * size is 4 KiB, dictionary size of 32 KiB or 64 KiB is good. If the 0567 * data compresses extremely well, even 128 KiB may be useful. 0568 * 0569 * The MicroLZMA format and this encoder variant were made with the EROFS 0570 * file system in mind. This format may be convenient in other embedded 0571 * uses too where many small streams are needed. XZ Embedded includes a 0572 * decoder for this format. 0573 * 0574 * \param strm Pointer to lzma_stream that is at least initialized 0575 * with LZMA_STREAM_INIT. 0576 * \param options Pointer to encoder options 0577 * 0578 * \return Possible lzma_ret values: 0579 * - LZMA_STREAM_END: All good. Check the amounts of input used 0580 * and output produced. Store the amount of input used 0581 * (uncompressed size) as it needs to be known to decompress 0582 * the data. 0583 * - LZMA_OPTIONS_ERROR 0584 * - LZMA_MEM_ERROR 0585 * - LZMA_PROG_ERROR: In addition to the generic reasons for this 0586 * error code, this may also be returned if there isn't enough 0587 * output space (6 bytes) to create a valid MicroLZMA stream. 0588 */ 0589 extern LZMA_API(lzma_ret) lzma_microlzma_encoder( 0590 lzma_stream *strm, const lzma_options_lzma *options) 0591 lzma_nothrow; 0592 0593 0594 /************ 0595 * Decoding * 0596 ************/ 0597 0598 /** 0599 * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream 0600 * being decoded has no integrity check. Note that when used with 0601 * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK 0602 * if LZMA_TELL_NO_CHECK is used. 0603 */ 0604 #define LZMA_TELL_NO_CHECK UINT32_C(0x01) 0605 0606 0607 /** 0608 * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input 0609 * stream has an integrity check, but the type of the integrity check is not 0610 * supported by this liblzma version or build. Such files can still be 0611 * decoded, but the integrity check cannot be verified. 0612 */ 0613 #define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02) 0614 0615 0616 /** 0617 * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type 0618 * of the integrity check is known. The type can then be got with 0619 * lzma_get_check(). 0620 */ 0621 #define LZMA_TELL_ANY_CHECK UINT32_C(0x04) 0622 0623 0624 /** 0625 * This flag makes lzma_code() not calculate and verify the integrity check 0626 * of the compressed data in .xz files. This means that invalid integrity 0627 * check values won't be detected and LZMA_DATA_ERROR won't be returned in 0628 * such cases. 0629 * 0630 * This flag only affects the checks of the compressed data itself; the CRC32 0631 * values in the .xz headers will still be verified normally. 0632 * 0633 * Don't use this flag unless you know what you are doing. Possible reasons 0634 * to use this flag: 0635 * 0636 * - Trying to recover data from a corrupt .xz file. 0637 * 0638 * - Speeding up decompression, which matters mostly with SHA-256 0639 * or with files that have compressed extremely well. It's recommended 0640 * to not use this flag for this purpose unless the file integrity is 0641 * verified externally in some other way. 0642 * 0643 * Support for this flag was added in liblzma 5.1.4beta. 0644 */ 0645 #define LZMA_IGNORE_CHECK UINT32_C(0x10) 0646 0647 0648 /** 0649 * This flag enables decoding of concatenated files with file formats that 0650 * allow concatenating compressed files as is. From the formats currently 0651 * supported by liblzma, only the .xz and .lz formats allow concatenated 0652 * files. Concatenated files are not allowed with the legacy .lzma format. 0653 * 0654 * This flag also affects the usage of the `action' argument for lzma_code(). 0655 * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END 0656 * unless LZMA_FINISH is used as `action'. Thus, the application has to set 0657 * LZMA_FINISH in the same way as it does when encoding. 0658 * 0659 * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH 0660 * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required. 0661 */ 0662 #define LZMA_CONCATENATED UINT32_C(0x08) 0663 0664 0665 /** 0666 * This flag makes the threaded decoder report errors (like LZMA_DATA_ERROR) 0667 * as soon as they are detected. This saves time when the application has no 0668 * interest in a partially decompressed truncated or corrupt file. Note that 0669 * due to timing randomness, if the same truncated or corrupt input is 0670 * decompressed multiple times with this flag, a different amount of output 0671 * may be produced by different runs, and even the error code might vary. 0672 * 0673 * When using LZMA_FAIL_FAST, it is recommended to use LZMA_FINISH to tell 0674 * the decoder when no more input will be coming because it can help fast 0675 * detection and reporting of truncated files. Note that in this situation 0676 * truncated files might be diagnosed with LZMA_DATA_ERROR instead of 0677 * LZMA_OK or LZMA_BUF_ERROR! 0678 * 0679 * Without this flag the threaded decoder will provide as much output as 0680 * possible at first and then report the pending error. This default behavior 0681 * matches the single-threaded decoder and provides repeatable behavior 0682 * with truncated or corrupt input. There are a few special cases where the 0683 * behavior can still differ like memory allocation failures (LZMA_MEM_ERROR). 0684 * 0685 * Single-threaded decoders currently ignore this flag. 0686 * 0687 * Support for this flag was added in liblzma 5.3.3alpha. Note that in older 0688 * versions this flag isn't supported (LZMA_OPTIONS_ERROR) even by functions 0689 * that ignore this flag in newer liblzma versions. 0690 */ 0691 #define LZMA_FAIL_FAST UINT32_C(0x20) 0692 0693 0694 /** 0695 * \brief Initialize .xz Stream decoder 0696 * 0697 * \param strm Pointer to lzma_stream that is at least initialized 0698 * with LZMA_STREAM_INIT. 0699 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 0700 * to effectively disable the limiter. liblzma 0701 * 5.2.3 and earlier don't allow 0 here and return 0702 * LZMA_PROG_ERROR; later versions treat 0 as if 1 0703 * had been specified. 0704 * \param flags Bitwise-or of zero or more of the decoder flags: 0705 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 0706 * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, 0707 * LZMA_CONCATENATED, LZMA_FAIL_FAST 0708 * 0709 * \return Possible lzma_ret values: 0710 * - LZMA_OK: Initialization was successful. 0711 * - LZMA_MEM_ERROR: Cannot allocate memory. 0712 * - LZMA_OPTIONS_ERROR: Unsupported flags 0713 * - LZMA_PROG_ERROR 0714 */ 0715 extern LZMA_API(lzma_ret) lzma_stream_decoder( 0716 lzma_stream *strm, uint64_t memlimit, uint32_t flags) 0717 lzma_nothrow lzma_attr_warn_unused_result; 0718 0719 0720 /** 0721 * \brief Initialize multithreaded .xz Stream decoder 0722 * 0723 * The decoder can decode multiple Blocks in parallel. This requires that each 0724 * Block Header contains the Compressed Size and Uncompressed size fields 0725 * which are added by the multi-threaded encoder, see lzma_stream_encoder_mt(). 0726 * 0727 * A Stream with one Block will only utilize one thread. A Stream with multiple 0728 * Blocks but without size information in Block Headers will be processed in 0729 * single-threaded mode in the same way as done by lzma_stream_decoder(). 0730 * Concatenated Streams are processed one Stream at a time; no inter-Stream 0731 * parallelization is done. 0732 * 0733 * This function behaves like lzma_stream_decoder() when options->threads == 1 0734 * and options->memlimit_threading <= 1. 0735 * 0736 * \param strm Pointer to lzma_stream that is at least initialized 0737 * with LZMA_STREAM_INIT. 0738 * \param options Pointer to multithreaded compression options 0739 * 0740 * \return Possible lzma_ret values: 0741 * - LZMA_OK: Initialization was successful. 0742 * - LZMA_MEM_ERROR: Cannot allocate memory. 0743 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 0744 * - LZMA_OPTIONS_ERROR: Unsupported flags. 0745 * - LZMA_PROG_ERROR 0746 */ 0747 extern LZMA_API(lzma_ret) lzma_stream_decoder_mt( 0748 lzma_stream *strm, const lzma_mt *options) 0749 lzma_nothrow lzma_attr_warn_unused_result; 0750 0751 0752 /** 0753 * \brief Decode .xz, .lzma, and .lz (lzip) files with autodetection 0754 * 0755 * This decoder autodetects between the .xz, .lzma, and .lz file formats, 0756 * and calls lzma_stream_decoder(), lzma_alone_decoder(), or 0757 * lzma_lzip_decoder() once the type of the input file has been detected. 0758 * 0759 * Support for .lz was added in 5.4.0. 0760 * 0761 * If the flag LZMA_CONCATENATED is used and the input is a .lzma file: 0762 * For historical reasons concatenated .lzma files aren't supported. 0763 * If there is trailing data after one .lzma stream, lzma_code() will 0764 * return LZMA_DATA_ERROR. (lzma_alone_decoder() doesn't have such a check 0765 * as it doesn't support any decoder flags. It will return LZMA_STREAM_END 0766 * after one .lzma stream.) 0767 * 0768 * \param strm Pointer to lzma_stream that is at least initialized 0769 * with LZMA_STREAM_INIT. 0770 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 0771 * to effectively disable the limiter. liblzma 0772 * 5.2.3 and earlier don't allow 0 here and return 0773 * LZMA_PROG_ERROR; later versions treat 0 as if 1 0774 * had been specified. 0775 * \param flags Bitwise-or of zero or more of the decoder flags: 0776 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 0777 * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, 0778 * LZMA_CONCATENATED, LZMA_FAIL_FAST 0779 * 0780 * \return Possible lzma_ret values: 0781 * - LZMA_OK: Initialization was successful. 0782 * - LZMA_MEM_ERROR: Cannot allocate memory. 0783 * - LZMA_OPTIONS_ERROR: Unsupported flags 0784 * - LZMA_PROG_ERROR 0785 */ 0786 extern LZMA_API(lzma_ret) lzma_auto_decoder( 0787 lzma_stream *strm, uint64_t memlimit, uint32_t flags) 0788 lzma_nothrow lzma_attr_warn_unused_result; 0789 0790 0791 /** 0792 * \brief Initialize .lzma decoder (legacy file format) 0793 * 0794 * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. 0795 * There is no need to use LZMA_FINISH, but it's allowed because it may 0796 * simplify certain types of applications. 0797 * 0798 * \param strm Pointer to lzma_stream that is at least initialized 0799 * with LZMA_STREAM_INIT. 0800 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 0801 * to effectively disable the limiter. liblzma 0802 * 5.2.3 and earlier don't allow 0 here and return 0803 * LZMA_PROG_ERROR; later versions treat 0 as if 1 0804 * had been specified. 0805 * 0806 * \return Possible lzma_ret values: 0807 * - LZMA_OK 0808 * - LZMA_MEM_ERROR 0809 * - LZMA_PROG_ERROR 0810 */ 0811 extern LZMA_API(lzma_ret) lzma_alone_decoder( 0812 lzma_stream *strm, uint64_t memlimit) 0813 lzma_nothrow lzma_attr_warn_unused_result; 0814 0815 0816 /** 0817 * \brief Initialize .lz (lzip) decoder (a foreign file format) 0818 * 0819 * This decoder supports the .lz format version 0 and the unextended .lz 0820 * format version 1: 0821 * 0822 * - Files in the format version 0 were produced by lzip 1.3 and older. 0823 * Such files aren't common but may be found from file archives 0824 * as a few source packages were released in this format. People 0825 * might have old personal files in this format too. Decompression 0826 * support for the format version 0 was removed in lzip 1.18. 0827 * 0828 * - lzip 1.3 added decompression support for .lz format version 1 files. 0829 * Compression support was added in lzip 1.4. In lzip 1.6 the .lz format 0830 * version 1 was extended to support the Sync Flush marker. This extension 0831 * is not supported by liblzma. lzma_code() will return LZMA_DATA_ERROR 0832 * at the location of the Sync Flush marker. In practice files with 0833 * the Sync Flush marker are very rare and thus liblzma can decompress 0834 * almost all .lz files. 0835 * 0836 * Just like with lzma_stream_decoder() for .xz files, LZMA_CONCATENATED 0837 * should be used when decompressing normal standalone .lz files. 0838 * 0839 * The .lz format allows putting non-.lz data at the end of a file after at 0840 * least one valid .lz member. That is, one can append custom data at the end 0841 * of a .lz file and the decoder is required to ignore it. In liblzma this 0842 * is relevant only when LZMA_CONCATENATED is used. In that case lzma_code() 0843 * will return LZMA_STREAM_END and leave lzma_stream.next_in pointing to 0844 * the first byte of the non-.lz data. An exception to this is if the first 0845 * 1-3 bytes of the non-.lz data are identical to the .lz magic bytes 0846 * (0x4C, 0x5A, 0x49, 0x50; "LZIP" in US-ASCII). In such a case the 1-3 bytes 0847 * will have been ignored by lzma_code(). If one wishes to locate the non-.lz 0848 * data reliably, one must ensure that the first byte isn't 0x4C. Actually 0849 * one should ensure that none of the first four bytes of trailing data are 0850 * equal to the magic bytes because lzip >= 1.20 requires it by default. 0851 * 0852 * \param strm Pointer to lzma_stream that is at least initialized 0853 * with LZMA_STREAM_INIT. 0854 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 0855 * to effectively disable the limiter. 0856 * \param flags Bitwise-or of flags, or zero for no flags. 0857 * All decoder flags listed above are supported 0858 * although only LZMA_CONCATENATED and (in very rare 0859 * cases) LZMA_IGNORE_CHECK are actually useful. 0860 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 0861 * and LZMA_FAIL_FAST do nothing. LZMA_TELL_ANY_CHECK 0862 * is supported for consistency only as CRC32 is 0863 * always used in the .lz format. 0864 * 0865 * \return Possible lzma_ret values: 0866 * - LZMA_OK: Initialization was successful. 0867 * - LZMA_MEM_ERROR: Cannot allocate memory. 0868 * - LZMA_OPTIONS_ERROR: Unsupported flags 0869 * - LZMA_PROG_ERROR 0870 */ 0871 extern LZMA_API(lzma_ret) lzma_lzip_decoder( 0872 lzma_stream *strm, uint64_t memlimit, uint32_t flags) 0873 lzma_nothrow lzma_attr_warn_unused_result; 0874 0875 0876 /** 0877 * \brief Single-call .xz Stream decoder 0878 * 0879 * \param memlimit Pointer to how much memory the decoder is allowed 0880 * to allocate. The value pointed by this pointer is 0881 * modified if and only if LZMA_MEMLIMIT_ERROR is 0882 * returned. 0883 * \param flags Bitwise-or of zero or more of the decoder flags: 0884 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 0885 * LZMA_IGNORE_CHECK, LZMA_CONCATENATED, 0886 * LZMA_FAIL_FAST. Note that LZMA_TELL_ANY_CHECK 0887 * is not allowed and will return LZMA_PROG_ERROR. 0888 * \param allocator lzma_allocator for custom allocator functions. 0889 * Set to NULL to use malloc() and free(). 0890 * \param in Beginning of the input buffer 0891 * \param in_pos The next byte will be read from in[*in_pos]. 0892 * *in_pos is updated only if decoding succeeds. 0893 * \param in_size Size of the input buffer; the first byte that 0894 * won't be read is in[in_size]. 0895 * \param[out] out Beginning of the output buffer 0896 * \param[out] out_pos The next byte will be written to out[*out_pos]. 0897 * *out_pos is updated only if decoding succeeds. 0898 * \param out_size Size of the out buffer; the first byte into 0899 * which no data is written to is out[out_size]. 0900 * 0901 * \return Possible lzma_ret values: 0902 * - LZMA_OK: Decoding was successful. 0903 * - LZMA_FORMAT_ERROR 0904 * - LZMA_OPTIONS_ERROR 0905 * - LZMA_DATA_ERROR 0906 * - LZMA_NO_CHECK: This can be returned only if using 0907 * the LZMA_TELL_NO_CHECK flag. 0908 * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using 0909 * the LZMA_TELL_UNSUPPORTED_CHECK flag. 0910 * - LZMA_MEM_ERROR 0911 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 0912 * The minimum required memlimit value was stored to *memlimit. 0913 * - LZMA_BUF_ERROR: Output buffer was too small. 0914 * - LZMA_PROG_ERROR 0915 */ 0916 extern LZMA_API(lzma_ret) lzma_stream_buffer_decode( 0917 uint64_t *memlimit, uint32_t flags, 0918 const lzma_allocator *allocator, 0919 const uint8_t *in, size_t *in_pos, size_t in_size, 0920 uint8_t *out, size_t *out_pos, size_t out_size) 0921 lzma_nothrow lzma_attr_warn_unused_result; 0922 0923 0924 /** 0925 * \brief MicroLZMA decoder 0926 * 0927 * See lzma_microlzma_encoder() for more information. 0928 * 0929 * The lzma_code() usage with this decoder is completely normal. The 0930 * special behavior of lzma_code() applies to lzma_microlzma_encoder() only. 0931 * 0932 * \param strm Pointer to lzma_stream that is at least initialized 0933 * with LZMA_STREAM_INIT. 0934 * \param comp_size Compressed size of the MicroLZMA stream. 0935 * The caller must somehow know this exactly. 0936 * \param uncomp_size Uncompressed size of the MicroLZMA stream. 0937 * If the exact uncompressed size isn't known, this 0938 * can be set to a value that is at most as big as 0939 * the exact uncompressed size would be, but then the 0940 * next argument uncomp_size_is_exact must be false. 0941 * \param uncomp_size_is_exact 0942 * If true, uncomp_size must be exactly correct. 0943 * This will improve error detection at the end of 0944 * the stream. If the exact uncompressed size isn't 0945 * known, this must be false. uncomp_size must still 0946 * be at most as big as the exact uncompressed size 0947 * is. Setting this to false when the exact size is 0948 * known will work but error detection at the end of 0949 * the stream will be weaker. 0950 * \param dict_size LZMA dictionary size that was used when 0951 * compressing the data. It is OK to use a bigger 0952 * value too but liblzma will then allocate more 0953 * memory than would actually be required and error 0954 * detection will be slightly worse. (Note that with 0955 * the implementation in XZ Embedded it doesn't 0956 * affect the memory usage if one specifies bigger 0957 * dictionary than actually required.) 0958 * 0959 * \return Possible lzma_ret values: 0960 * - LZMA_OK 0961 * - LZMA_MEM_ERROR 0962 * - LZMA_OPTIONS_ERROR 0963 * - LZMA_PROG_ERROR 0964 */ 0965 extern LZMA_API(lzma_ret) lzma_microlzma_decoder( 0966 lzma_stream *strm, uint64_t comp_size, 0967 uint64_t uncomp_size, lzma_bool uncomp_size_is_exact, 0968 uint32_t dict_size) lzma_nothrow;
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |