12940b44dSPeter Avalos /** 22940b44dSPeter Avalos * \file lzma/container.h 32940b44dSPeter Avalos * \brief File formats 42940b44dSPeter Avalos */ 52940b44dSPeter Avalos 62940b44dSPeter Avalos /* 72940b44dSPeter Avalos * Author: Lasse Collin 82940b44dSPeter Avalos * 92940b44dSPeter Avalos * This file has been put into the public domain. 102940b44dSPeter Avalos * You can do whatever you want with this file. 112940b44dSPeter Avalos * 122940b44dSPeter Avalos * See ../lzma.h for information about liblzma as a whole. 132940b44dSPeter Avalos */ 142940b44dSPeter Avalos 152940b44dSPeter Avalos #ifndef LZMA_H_INTERNAL 162940b44dSPeter Avalos # error Never include this file directly. Use <lzma.h> instead. 172940b44dSPeter Avalos #endif 182940b44dSPeter Avalos 192940b44dSPeter Avalos 202940b44dSPeter Avalos /************ 212940b44dSPeter Avalos * Encoding * 222940b44dSPeter Avalos ************/ 232940b44dSPeter Avalos 242940b44dSPeter Avalos /** 252940b44dSPeter Avalos * \brief Default compression preset 262940b44dSPeter Avalos * 272940b44dSPeter Avalos * It's not straightforward to recommend a default preset, because in some 282940b44dSPeter Avalos * cases keeping the resource usage relatively low is more important that 292940b44dSPeter Avalos * getting the maximum compression ratio. 302940b44dSPeter Avalos */ 312940b44dSPeter Avalos #define LZMA_PRESET_DEFAULT UINT32_C(6) 322940b44dSPeter Avalos 332940b44dSPeter Avalos 342940b44dSPeter Avalos /** 352940b44dSPeter Avalos * \brief Mask for preset level 362940b44dSPeter Avalos * 372940b44dSPeter Avalos * This is useful only if you need to extract the level from the preset 382940b44dSPeter Avalos * variable. That should be rare. 392940b44dSPeter Avalos */ 402940b44dSPeter Avalos #define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) 412940b44dSPeter Avalos 422940b44dSPeter Avalos 432940b44dSPeter Avalos /* 442940b44dSPeter Avalos * Preset flags 452940b44dSPeter Avalos * 462940b44dSPeter Avalos * Currently only one flag is defined. 472940b44dSPeter Avalos */ 482940b44dSPeter Avalos 492940b44dSPeter Avalos /** 502940b44dSPeter Avalos * \brief Extreme compression preset 512940b44dSPeter Avalos * 522940b44dSPeter Avalos * This flag modifies the preset to make the encoding significantly slower 532940b44dSPeter Avalos * while improving the compression ratio only marginally. This is useful 542940b44dSPeter Avalos * when you don't mind wasting time to get as small result as possible. 552940b44dSPeter Avalos * 562940b44dSPeter Avalos * This flag doesn't affect the memory usage requirements of the decoder (at 572940b44dSPeter Avalos * least not significantly). The memory usage of the encoder may be increased 582940b44dSPeter Avalos * a little but only at the lowest preset levels (0-3). 592940b44dSPeter Avalos */ 602940b44dSPeter Avalos #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) 612940b44dSPeter Avalos 622940b44dSPeter Avalos 632940b44dSPeter Avalos /** 6415ab8c86SJohn Marino * \brief Multithreading options 6515ab8c86SJohn Marino */ 6615ab8c86SJohn Marino typedef struct { 6715ab8c86SJohn Marino /** 6815ab8c86SJohn Marino * \brief Flags 6915ab8c86SJohn Marino * 7015ab8c86SJohn Marino * Set this to zero if no flags are wanted. 7115ab8c86SJohn Marino * 7215ab8c86SJohn Marino * No flags are currently supported. 7315ab8c86SJohn Marino */ 7415ab8c86SJohn Marino uint32_t flags; 7515ab8c86SJohn Marino 7615ab8c86SJohn Marino /** 7715ab8c86SJohn Marino * \brief Number of worker threads to use 7815ab8c86SJohn Marino */ 7915ab8c86SJohn Marino uint32_t threads; 8015ab8c86SJohn Marino 8115ab8c86SJohn Marino /** 8215ab8c86SJohn Marino * \brief Maximum uncompressed size of a Block 8315ab8c86SJohn Marino * 8415ab8c86SJohn Marino * The encoder will start a new .xz Block every block_size bytes. 8515ab8c86SJohn Marino * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code() 8615ab8c86SJohn Marino * the caller may tell liblzma to start a new Block earlier. 8715ab8c86SJohn Marino * 8815ab8c86SJohn Marino * With LZMA2, a recommended block size is 2-4 times the LZMA2 8915ab8c86SJohn Marino * dictionary size. With very small dictionaries, it is recommended 9015ab8c86SJohn Marino * to use at least 1 MiB block size for good compression ratio, even 9115ab8c86SJohn Marino * if this is more than four times the dictionary size. Note that 9215ab8c86SJohn Marino * these are only recommendations for typical use cases; feel free 9315ab8c86SJohn Marino * to use other values. Just keep in mind that using a block size 9415ab8c86SJohn Marino * less than the LZMA2 dictionary size is waste of RAM. 9515ab8c86SJohn Marino * 9615ab8c86SJohn Marino * Set this to 0 to let liblzma choose the block size depending 9715ab8c86SJohn Marino * on the compression options. For LZMA2 it will be 3*dict_size 9815ab8c86SJohn Marino * or 1 MiB, whichever is more. 9915ab8c86SJohn Marino * 10015ab8c86SJohn Marino * For each thread, about 3 * block_size bytes of memory will be 10115ab8c86SJohn Marino * allocated. This may change in later liblzma versions. If so, 10215ab8c86SJohn Marino * the memory usage will probably be reduced, not increased. 10315ab8c86SJohn Marino */ 10415ab8c86SJohn Marino uint64_t block_size; 10515ab8c86SJohn Marino 10615ab8c86SJohn Marino /** 10715ab8c86SJohn Marino * \brief Timeout to allow lzma_code() to return early 10815ab8c86SJohn Marino * 10915ab8c86SJohn Marino * Multithreading can make liblzma to consume input and produce 11015ab8c86SJohn Marino * output in a very bursty way: it may first read a lot of input 11115ab8c86SJohn Marino * to fill internal buffers, then no input or output occurs for 11215ab8c86SJohn Marino * a while. 11315ab8c86SJohn Marino * 11415ab8c86SJohn Marino * In single-threaded mode, lzma_code() won't return until it has 11515ab8c86SJohn Marino * either consumed all the input or filled the output buffer. If 11615ab8c86SJohn Marino * this is done in multithreaded mode, it may cause a call 11715ab8c86SJohn Marino * lzma_code() to take even tens of seconds, which isn't acceptable 11815ab8c86SJohn Marino * in all applications. 11915ab8c86SJohn Marino * 12015ab8c86SJohn Marino * To avoid very long blocking times in lzma_code(), a timeout 12115ab8c86SJohn Marino * (in milliseconds) may be set here. If lzma_code() would block 12215ab8c86SJohn Marino * longer than this number of milliseconds, it will return with 12315ab8c86SJohn Marino * LZMA_OK. Reasonable values are 100 ms or more. The xz command 12415ab8c86SJohn Marino * line tool uses 300 ms. 12515ab8c86SJohn Marino * 12615ab8c86SJohn Marino * If long blocking times are fine for you, set timeout to a special 12715ab8c86SJohn Marino * value of 0, which will disable the timeout mechanism and will make 12815ab8c86SJohn Marino * lzma_code() block until all the input is consumed or the output 12915ab8c86SJohn Marino * buffer has been filled. 13015ab8c86SJohn Marino * 13115ab8c86SJohn Marino * \note Even with a timeout, lzma_code() might sometimes take 13215ab8c86SJohn Marino * somewhat long time to return. No timing guarantees 13315ab8c86SJohn Marino * are made. 13415ab8c86SJohn Marino */ 13515ab8c86SJohn Marino uint32_t timeout; 13615ab8c86SJohn Marino 13715ab8c86SJohn Marino /** 13815ab8c86SJohn Marino * \brief Compression preset (level and possible flags) 13915ab8c86SJohn Marino * 14015ab8c86SJohn Marino * The preset is set just like with lzma_easy_encoder(). 14115ab8c86SJohn Marino * The preset is ignored if filters below is non-NULL. 14215ab8c86SJohn Marino */ 14315ab8c86SJohn Marino uint32_t preset; 14415ab8c86SJohn Marino 14515ab8c86SJohn Marino /** 14615ab8c86SJohn Marino * \brief Filter chain (alternative to a preset) 14715ab8c86SJohn Marino * 14815ab8c86SJohn Marino * If this is NULL, the preset above is used. Otherwise the preset 14915ab8c86SJohn Marino * is ignored and the filter chain specified here is used. 15015ab8c86SJohn Marino */ 15115ab8c86SJohn Marino const lzma_filter *filters; 15215ab8c86SJohn Marino 15315ab8c86SJohn Marino /** 15415ab8c86SJohn Marino * \brief Integrity check type 15515ab8c86SJohn Marino * 15615ab8c86SJohn Marino * See check.h for available checks. The xz command line tool 15715ab8c86SJohn Marino * defaults to LZMA_CHECK_CRC64, which is a good choice if you 15815ab8c86SJohn Marino * are unsure. 15915ab8c86SJohn Marino */ 16015ab8c86SJohn Marino lzma_check check; 16115ab8c86SJohn Marino 16215ab8c86SJohn Marino /* 16315ab8c86SJohn Marino * Reserved space to allow possible future extensions without 16415ab8c86SJohn Marino * breaking the ABI. You should not touch these, because the names 16515ab8c86SJohn Marino * of these variables may change. These are and will never be used 16615ab8c86SJohn Marino * with the currently supported options, so it is safe to leave these 16715ab8c86SJohn Marino * uninitialized. 16815ab8c86SJohn Marino */ 16915ab8c86SJohn Marino lzma_reserved_enum reserved_enum1; 17015ab8c86SJohn Marino lzma_reserved_enum reserved_enum2; 17115ab8c86SJohn Marino lzma_reserved_enum reserved_enum3; 17215ab8c86SJohn Marino uint32_t reserved_int1; 17315ab8c86SJohn Marino uint32_t reserved_int2; 17415ab8c86SJohn Marino uint32_t reserved_int3; 17515ab8c86SJohn Marino uint32_t reserved_int4; 17615ab8c86SJohn Marino uint64_t reserved_int5; 17715ab8c86SJohn Marino uint64_t reserved_int6; 17815ab8c86SJohn Marino uint64_t reserved_int7; 17915ab8c86SJohn Marino uint64_t reserved_int8; 18015ab8c86SJohn Marino void *reserved_ptr1; 18115ab8c86SJohn Marino void *reserved_ptr2; 18215ab8c86SJohn Marino void *reserved_ptr3; 18315ab8c86SJohn Marino void *reserved_ptr4; 18415ab8c86SJohn Marino 18515ab8c86SJohn Marino } lzma_mt; 18615ab8c86SJohn Marino 18715ab8c86SJohn Marino 18815ab8c86SJohn Marino /** 1892940b44dSPeter Avalos * \brief Calculate approximate memory usage of easy encoder 1902940b44dSPeter Avalos * 1912940b44dSPeter Avalos * This function is a wrapper for lzma_raw_encoder_memusage(). 1922940b44dSPeter Avalos * 1932940b44dSPeter Avalos * \param preset Compression preset (level and possible flags) 194114db65bSPeter Avalos * 195114db65bSPeter Avalos * \return Number of bytes of memory required for the given 196114db65bSPeter Avalos * preset when encoding. If an error occurs, for example 197114db65bSPeter Avalos * due to unsupported preset, UINT64_MAX is returned. 1982940b44dSPeter Avalos */ 1992940b44dSPeter Avalos extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) 2002940b44dSPeter Avalos lzma_nothrow lzma_attr_pure; 2012940b44dSPeter Avalos 2022940b44dSPeter Avalos 2032940b44dSPeter Avalos /** 2042940b44dSPeter Avalos * \brief Calculate approximate decoder memory usage of a preset 2052940b44dSPeter Avalos * 2062940b44dSPeter Avalos * This function is a wrapper for lzma_raw_decoder_memusage(). 2072940b44dSPeter Avalos * 2082940b44dSPeter Avalos * \param preset Compression preset (level and possible flags) 209114db65bSPeter Avalos * 210114db65bSPeter Avalos * \return Number of bytes of memory required to decompress a file 211114db65bSPeter Avalos * that was compressed using the given preset. If an error 212114db65bSPeter Avalos * occurs, for example due to unsupported preset, UINT64_MAX 213114db65bSPeter Avalos * is returned. 2142940b44dSPeter Avalos */ 2152940b44dSPeter Avalos extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) 2162940b44dSPeter Avalos lzma_nothrow lzma_attr_pure; 2172940b44dSPeter Avalos 2182940b44dSPeter Avalos 2192940b44dSPeter Avalos /** 2202940b44dSPeter Avalos * \brief Initialize .xz Stream encoder using a preset number 2212940b44dSPeter Avalos * 2222940b44dSPeter Avalos * This function is intended for those who just want to use the basic features 2232940b44dSPeter Avalos * if liblzma (that is, most developers out there). 2242940b44dSPeter Avalos * 2252940b44dSPeter Avalos * \param strm Pointer to lzma_stream that is at least initialized 2262940b44dSPeter Avalos * with LZMA_STREAM_INIT. 2272940b44dSPeter Avalos * \param preset Compression preset to use. A preset consist of level 2282940b44dSPeter Avalos * number and zero or more flags. Usually flags aren't 2292940b44dSPeter Avalos * used, so preset is simply a number [0, 9] which match 2302940b44dSPeter Avalos * the options -0 ... -9 of the xz command line tool. 2312940b44dSPeter Avalos * Additional flags can be be set using bitwise-or with 2322940b44dSPeter Avalos * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME. 2332940b44dSPeter Avalos * \param check Integrity check type to use. See check.h for available 2342940b44dSPeter Avalos * checks. The xz command line tool defaults to 2352940b44dSPeter Avalos * LZMA_CHECK_CRC64, which is a good choice if you are 2362940b44dSPeter Avalos * unsure. LZMA_CHECK_CRC32 is good too as long as the 2372940b44dSPeter Avalos * uncompressed file is not many gigabytes. 2382940b44dSPeter Avalos * 2392940b44dSPeter Avalos * \return - LZMA_OK: Initialization succeeded. Use lzma_code() to 2402940b44dSPeter Avalos * encode your data. 2412940b44dSPeter Avalos * - LZMA_MEM_ERROR: Memory allocation failed. 2422940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR: The given compression preset is not 2432940b44dSPeter Avalos * supported by this build of liblzma. 2442940b44dSPeter Avalos * - LZMA_UNSUPPORTED_CHECK: The given check type is not 2452940b44dSPeter Avalos * supported by this liblzma build. 2462940b44dSPeter Avalos * - LZMA_PROG_ERROR: One or more of the parameters have values 2472940b44dSPeter Avalos * that will never be valid. For example, strm == NULL. 2482940b44dSPeter Avalos * 2492940b44dSPeter Avalos * If initialization fails (return value is not LZMA_OK), all the memory 2502940b44dSPeter Avalos * allocated for *strm by liblzma is always freed. Thus, there is no need 2512940b44dSPeter Avalos * to call lzma_end() after failed initialization. 2522940b44dSPeter Avalos * 2532940b44dSPeter Avalos * If initialization succeeds, use lzma_code() to do the actual encoding. 2542940b44dSPeter Avalos * Valid values for `action' (the second argument of lzma_code()) are 2552940b44dSPeter Avalos * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, 2562940b44dSPeter Avalos * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH. 2572940b44dSPeter Avalos */ 2582940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_easy_encoder( 2592940b44dSPeter Avalos lzma_stream *strm, uint32_t preset, lzma_check check) 2602940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 2612940b44dSPeter Avalos 2622940b44dSPeter Avalos 2632940b44dSPeter Avalos /** 2642940b44dSPeter Avalos * \brief Single-call .xz Stream encoding using a preset number 2652940b44dSPeter Avalos * 2662940b44dSPeter Avalos * The maximum required output buffer size can be calculated with 2672940b44dSPeter Avalos * lzma_stream_buffer_bound(). 2682940b44dSPeter Avalos * 2692940b44dSPeter Avalos * \param preset Compression preset to use. See the description 2702940b44dSPeter Avalos * in lzma_easy_encoder(). 2712940b44dSPeter Avalos * \param check Type of the integrity check to calculate from 2722940b44dSPeter Avalos * uncompressed data. 2732940b44dSPeter Avalos * \param allocator lzma_allocator for custom allocator functions. 2742940b44dSPeter Avalos * Set to NULL to use malloc() and free(). 2752940b44dSPeter Avalos * \param in Beginning of the input buffer 2762940b44dSPeter Avalos * \param in_size Size of the input buffer 2772940b44dSPeter Avalos * \param out Beginning of the output buffer 2782940b44dSPeter Avalos * \param out_pos The next byte will be written to out[*out_pos]. 2792940b44dSPeter Avalos * *out_pos is updated only if encoding succeeds. 2802940b44dSPeter Avalos * \param out_size Size of the out buffer; the first byte into 2812940b44dSPeter Avalos * which no data is written to is out[out_size]. 2822940b44dSPeter Avalos * 2832940b44dSPeter Avalos * \return - LZMA_OK: Encoding was successful. 2842940b44dSPeter Avalos * - LZMA_BUF_ERROR: Not enough output buffer space. 285114db65bSPeter Avalos * - LZMA_UNSUPPORTED_CHECK 2862940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR 2872940b44dSPeter Avalos * - LZMA_MEM_ERROR 2882940b44dSPeter Avalos * - LZMA_DATA_ERROR 2892940b44dSPeter Avalos * - LZMA_PROG_ERROR 2902940b44dSPeter Avalos */ 2912940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( 2922940b44dSPeter Avalos uint32_t preset, lzma_check check, 29315ab8c86SJohn Marino const lzma_allocator *allocator, 29415ab8c86SJohn Marino const uint8_t *in, size_t in_size, 2952940b44dSPeter Avalos uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; 2962940b44dSPeter Avalos 2972940b44dSPeter Avalos 2982940b44dSPeter Avalos /** 2992940b44dSPeter Avalos * \brief Initialize .xz Stream encoder using a custom filter chain 3002940b44dSPeter Avalos * 3012940b44dSPeter Avalos * \param strm Pointer to properly prepared lzma_stream 3022940b44dSPeter Avalos * \param filters Array of filters. This must be terminated with 3032940b44dSPeter Avalos * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for 3042940b44dSPeter Avalos * more information. 3052940b44dSPeter Avalos * \param check Type of the integrity check to calculate from 3062940b44dSPeter Avalos * uncompressed data. 3072940b44dSPeter Avalos * 3082940b44dSPeter Avalos * \return - LZMA_OK: Initialization was successful. 3092940b44dSPeter Avalos * - LZMA_MEM_ERROR 310114db65bSPeter Avalos * - LZMA_UNSUPPORTED_CHECK 3112940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR 3122940b44dSPeter Avalos * - LZMA_PROG_ERROR 3132940b44dSPeter Avalos */ 3142940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, 3152940b44dSPeter Avalos const lzma_filter *filters, lzma_check check) 3162940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 3172940b44dSPeter Avalos 3182940b44dSPeter Avalos 3192940b44dSPeter Avalos /** 32015ab8c86SJohn Marino * \brief Calculate approximate memory usage of multithreaded .xz encoder 32115ab8c86SJohn Marino * 32215ab8c86SJohn Marino * Since doing the encoding in threaded mode doesn't affect the memory 32315ab8c86SJohn Marino * requirements of single-threaded decompressor, you can use 32415ab8c86SJohn Marino * lzma_easy_decoder_memusage(options->preset) or 32515ab8c86SJohn Marino * lzma_raw_decoder_memusage(options->filters) to calculate 32615ab8c86SJohn Marino * the decompressor memory requirements. 32715ab8c86SJohn Marino * 32815ab8c86SJohn Marino * \param options Compression options 32915ab8c86SJohn Marino * 33015ab8c86SJohn Marino * \return Number of bytes of memory required for encoding with the 33115ab8c86SJohn Marino * given options. If an error occurs, for example due to 33215ab8c86SJohn Marino * unsupported preset or filter chain, UINT64_MAX is returned. 33315ab8c86SJohn Marino */ 33415ab8c86SJohn Marino extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( 33515ab8c86SJohn Marino const lzma_mt *options) lzma_nothrow lzma_attr_pure; 33615ab8c86SJohn Marino 33715ab8c86SJohn Marino 33815ab8c86SJohn Marino /** 33915ab8c86SJohn Marino * \brief Initialize multithreaded .xz Stream encoder 34015ab8c86SJohn Marino * 34115ab8c86SJohn Marino * This provides the functionality of lzma_easy_encoder() and 34215ab8c86SJohn Marino * lzma_stream_encoder() as a single function for multithreaded use. 34315ab8c86SJohn Marino * 34415ab8c86SJohn Marino * The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH, 34515ab8c86SJohn Marino * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be 34615ab8c86SJohn Marino * added in the future. 34715ab8c86SJohn Marino * 34815ab8c86SJohn Marino * \param strm Pointer to properly prepared lzma_stream 34915ab8c86SJohn Marino * \param options Pointer to multithreaded compression options 35015ab8c86SJohn Marino * 35115ab8c86SJohn Marino * \return - LZMA_OK 35215ab8c86SJohn Marino * - LZMA_MEM_ERROR 35315ab8c86SJohn Marino * - LZMA_UNSUPPORTED_CHECK 35415ab8c86SJohn Marino * - LZMA_OPTIONS_ERROR 35515ab8c86SJohn Marino * - LZMA_PROG_ERROR 35615ab8c86SJohn Marino */ 35715ab8c86SJohn Marino extern LZMA_API(lzma_ret) lzma_stream_encoder_mt( 35815ab8c86SJohn Marino lzma_stream *strm, const lzma_mt *options) 35915ab8c86SJohn Marino lzma_nothrow lzma_attr_warn_unused_result; 36015ab8c86SJohn Marino 36115ab8c86SJohn Marino 36215ab8c86SJohn Marino /** 3632940b44dSPeter Avalos * \brief Initialize .lzma encoder (legacy file format) 3642940b44dSPeter Avalos * 3652940b44dSPeter Avalos * The .lzma format is sometimes called the LZMA_Alone format, which is the 3662940b44dSPeter Avalos * reason for the name of this function. The .lzma format supports only the 3672940b44dSPeter Avalos * LZMA1 filter. There is no support for integrity checks like CRC32. 3682940b44dSPeter Avalos * 3692940b44dSPeter Avalos * Use this function if and only if you need to create files readable by 3702940b44dSPeter Avalos * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format 3712940b44dSPeter Avalos * is strongly recommended. 3722940b44dSPeter Avalos * 3732940b44dSPeter Avalos * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH. 3742940b44dSPeter Avalos * No kind of flushing is supported, because the file format doesn't make 3752940b44dSPeter Avalos * it possible. 3762940b44dSPeter Avalos * 3772940b44dSPeter Avalos * \return - LZMA_OK 3782940b44dSPeter Avalos * - LZMA_MEM_ERROR 3792940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR 3802940b44dSPeter Avalos * - LZMA_PROG_ERROR 3812940b44dSPeter Avalos */ 3822940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_alone_encoder( 3832940b44dSPeter Avalos lzma_stream *strm, const lzma_options_lzma *options) 3842940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 3852940b44dSPeter Avalos 3862940b44dSPeter Avalos 3872940b44dSPeter Avalos /** 3882940b44dSPeter Avalos * \brief Calculate output buffer size for single-call Stream encoder 3892940b44dSPeter Avalos * 3902940b44dSPeter Avalos * When trying to compress uncompressible data, the encoded size will be 3912940b44dSPeter Avalos * slightly bigger than the input data. This function calculates how much 3922940b44dSPeter Avalos * output buffer space is required to be sure that lzma_stream_buffer_encode() 3932940b44dSPeter Avalos * doesn't return LZMA_BUF_ERROR. 3942940b44dSPeter Avalos * 3952940b44dSPeter Avalos * The calculated value is not exact, but it is guaranteed to be big enough. 3962940b44dSPeter Avalos * The actual maximum output space required may be slightly smaller (up to 3972940b44dSPeter Avalos * about 100 bytes). This should not be a problem in practice. 3982940b44dSPeter Avalos * 3992940b44dSPeter Avalos * If the calculated maximum size doesn't fit into size_t or would make the 4002940b44dSPeter Avalos * Stream grow past LZMA_VLI_MAX (which should never happen in practice), 4012940b44dSPeter Avalos * zero is returned to indicate the error. 4022940b44dSPeter Avalos * 4032940b44dSPeter Avalos * \note The limit calculated by this function applies only to 4042940b44dSPeter Avalos * single-call encoding. Multi-call encoding may (and probably 4052940b44dSPeter Avalos * will) have larger maximum expansion when encoding 4062940b44dSPeter Avalos * uncompressible data. Currently there is no function to 4072940b44dSPeter Avalos * calculate the maximum expansion of multi-call encoding. 4082940b44dSPeter Avalos */ 4092940b44dSPeter Avalos extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) 4102940b44dSPeter Avalos lzma_nothrow; 4112940b44dSPeter Avalos 4122940b44dSPeter Avalos 4132940b44dSPeter Avalos /** 4142940b44dSPeter Avalos * \brief Single-call .xz Stream encoder 4152940b44dSPeter Avalos * 4162940b44dSPeter Avalos * \param filters Array of filters. This must be terminated with 4172940b44dSPeter Avalos * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h 4182940b44dSPeter Avalos * for more information. 4192940b44dSPeter Avalos * \param check Type of the integrity check to calculate from 4202940b44dSPeter Avalos * uncompressed data. 4212940b44dSPeter Avalos * \param allocator lzma_allocator for custom allocator functions. 4222940b44dSPeter Avalos * Set to NULL to use malloc() and free(). 4232940b44dSPeter Avalos * \param in Beginning of the input buffer 4242940b44dSPeter Avalos * \param in_size Size of the input buffer 4252940b44dSPeter Avalos * \param out Beginning of the output buffer 4262940b44dSPeter Avalos * \param out_pos The next byte will be written to out[*out_pos]. 4272940b44dSPeter Avalos * *out_pos is updated only if encoding succeeds. 4282940b44dSPeter Avalos * \param out_size Size of the out buffer; the first byte into 4292940b44dSPeter Avalos * which no data is written to is out[out_size]. 4302940b44dSPeter Avalos * 4312940b44dSPeter Avalos * \return - LZMA_OK: Encoding was successful. 4322940b44dSPeter Avalos * - LZMA_BUF_ERROR: Not enough output buffer space. 433114db65bSPeter Avalos * - LZMA_UNSUPPORTED_CHECK 4342940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR 4352940b44dSPeter Avalos * - LZMA_MEM_ERROR 4362940b44dSPeter Avalos * - LZMA_DATA_ERROR 4372940b44dSPeter Avalos * - LZMA_PROG_ERROR 4382940b44dSPeter Avalos */ 4392940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( 4402940b44dSPeter Avalos lzma_filter *filters, lzma_check check, 44115ab8c86SJohn Marino const lzma_allocator *allocator, 44215ab8c86SJohn Marino const uint8_t *in, size_t in_size, 4432940b44dSPeter Avalos uint8_t *out, size_t *out_pos, size_t out_size) 4442940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 4452940b44dSPeter Avalos 4462940b44dSPeter Avalos 4472940b44dSPeter Avalos /************ 4482940b44dSPeter Avalos * Decoding * 4492940b44dSPeter Avalos ************/ 4502940b44dSPeter Avalos 4512940b44dSPeter Avalos /** 4522940b44dSPeter Avalos * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream 4532940b44dSPeter Avalos * being decoded has no integrity check. Note that when used with 4542940b44dSPeter Avalos * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK 4552940b44dSPeter Avalos * if LZMA_TELL_NO_CHECK is used. 4562940b44dSPeter Avalos */ 4572940b44dSPeter Avalos #define LZMA_TELL_NO_CHECK UINT32_C(0x01) 4582940b44dSPeter Avalos 4592940b44dSPeter Avalos 4602940b44dSPeter Avalos /** 4612940b44dSPeter Avalos * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input 4622940b44dSPeter Avalos * stream has an integrity check, but the type of the integrity check is not 4632940b44dSPeter Avalos * supported by this liblzma version or build. Such files can still be 4642940b44dSPeter Avalos * decoded, but the integrity check cannot be verified. 4652940b44dSPeter Avalos */ 4662940b44dSPeter Avalos #define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02) 4672940b44dSPeter Avalos 4682940b44dSPeter Avalos 4692940b44dSPeter Avalos /** 4702940b44dSPeter Avalos * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type 4712940b44dSPeter Avalos * of the integrity check is known. The type can then be got with 4722940b44dSPeter Avalos * lzma_get_check(). 4732940b44dSPeter Avalos */ 4742940b44dSPeter Avalos #define LZMA_TELL_ANY_CHECK UINT32_C(0x04) 4752940b44dSPeter Avalos 4762940b44dSPeter Avalos 4772940b44dSPeter Avalos /** 47815ab8c86SJohn Marino * This flag makes lzma_code() not calculate and verify the integrity check 47915ab8c86SJohn Marino * of the compressed data in .xz files. This means that invalid integrity 48015ab8c86SJohn Marino * check values won't be detected and LZMA_DATA_ERROR won't be returned in 48115ab8c86SJohn Marino * such cases. 48215ab8c86SJohn Marino * 48315ab8c86SJohn Marino * This flag only affects the checks of the compressed data itself; the CRC32 48415ab8c86SJohn Marino * values in the .xz headers will still be verified normally. 48515ab8c86SJohn Marino * 48615ab8c86SJohn Marino * Don't use this flag unless you know what you are doing. Possible reasons 48715ab8c86SJohn Marino * to use this flag: 48815ab8c86SJohn Marino * 48915ab8c86SJohn Marino * - Trying to recover data from a corrupt .xz file. 49015ab8c86SJohn Marino * 49115ab8c86SJohn Marino * - Speeding up decompression, which matters mostly with SHA-256 49215ab8c86SJohn Marino * or with files that have compressed extremely well. It's recommended 49315ab8c86SJohn Marino * to not use this flag for this purpose unless the file integrity is 49415ab8c86SJohn Marino * verified externally in some other way. 49515ab8c86SJohn Marino * 49615ab8c86SJohn Marino * Support for this flag was added in liblzma 5.1.4beta. 49715ab8c86SJohn Marino */ 49815ab8c86SJohn Marino #define LZMA_IGNORE_CHECK UINT32_C(0x10) 49915ab8c86SJohn Marino 50015ab8c86SJohn Marino 50115ab8c86SJohn Marino /** 5022940b44dSPeter Avalos * This flag enables decoding of concatenated files with file formats that 5032940b44dSPeter Avalos * allow concatenating compressed files as is. From the formats currently 5042940b44dSPeter Avalos * supported by liblzma, only the .xz format allows concatenated files. 5052940b44dSPeter Avalos * Concatenated files are not allowed with the legacy .lzma format. 5062940b44dSPeter Avalos * 5072940b44dSPeter Avalos * This flag also affects the usage of the `action' argument for lzma_code(). 5082940b44dSPeter Avalos * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END 5092940b44dSPeter Avalos * unless LZMA_FINISH is used as `action'. Thus, the application has to set 5102940b44dSPeter Avalos * LZMA_FINISH in the same way as it does when encoding. 5112940b44dSPeter Avalos * 5122940b44dSPeter Avalos * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH 5132940b44dSPeter Avalos * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required. 5142940b44dSPeter Avalos */ 5152940b44dSPeter Avalos #define LZMA_CONCATENATED UINT32_C(0x08) 5162940b44dSPeter Avalos 5172940b44dSPeter Avalos 5182940b44dSPeter Avalos /** 5192940b44dSPeter Avalos * \brief Initialize .xz Stream decoder 5202940b44dSPeter Avalos * 5212940b44dSPeter Avalos * \param strm Pointer to properly prepared lzma_stream 5222940b44dSPeter Avalos * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 523*46a2189dSzrj * to effectively disable the limiter. liblzma 524*46a2189dSzrj * 5.2.3 and earlier don't allow 0 here and return 525*46a2189dSzrj * LZMA_PROG_ERROR; later versions treat 0 as if 1 526*46a2189dSzrj * had been specified. 5272940b44dSPeter Avalos * \param flags Bitwise-or of zero or more of the decoder flags: 5282940b44dSPeter Avalos * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 5292940b44dSPeter Avalos * LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED 5302940b44dSPeter Avalos * 5312940b44dSPeter Avalos * \return - LZMA_OK: Initialization was successful. 5322940b44dSPeter Avalos * - LZMA_MEM_ERROR: Cannot allocate memory. 5332940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR: Unsupported flags 5342940b44dSPeter Avalos * - LZMA_PROG_ERROR 5352940b44dSPeter Avalos */ 5362940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_stream_decoder( 5372940b44dSPeter Avalos lzma_stream *strm, uint64_t memlimit, uint32_t flags) 5382940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 5392940b44dSPeter Avalos 5402940b44dSPeter Avalos 5412940b44dSPeter Avalos /** 5422940b44dSPeter Avalos * \brief Decode .xz Streams and .lzma files with autodetection 5432940b44dSPeter Avalos * 5442940b44dSPeter Avalos * This decoder autodetects between the .xz and .lzma file formats, and 5452940b44dSPeter Avalos * calls lzma_stream_decoder() or lzma_alone_decoder() once the type 5462940b44dSPeter Avalos * of the input file has been detected. 5472940b44dSPeter Avalos * 5482940b44dSPeter Avalos * \param strm Pointer to properly prepared lzma_stream 5492940b44dSPeter Avalos * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 550*46a2189dSzrj * to effectively disable the limiter. liblzma 551*46a2189dSzrj * 5.2.3 and earlier don't allow 0 here and return 552*46a2189dSzrj * LZMA_PROG_ERROR; later versions treat 0 as if 1 553*46a2189dSzrj * had been specified. 5542940b44dSPeter Avalos * \param flags Bitwise-or of flags, or zero for no flags. 5552940b44dSPeter Avalos * 5562940b44dSPeter Avalos * \return - LZMA_OK: Initialization was successful. 5572940b44dSPeter Avalos * - LZMA_MEM_ERROR: Cannot allocate memory. 5582940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR: Unsupported flags 5592940b44dSPeter Avalos * - LZMA_PROG_ERROR 5602940b44dSPeter Avalos */ 5612940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_auto_decoder( 5622940b44dSPeter Avalos lzma_stream *strm, uint64_t memlimit, uint32_t flags) 5632940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 5642940b44dSPeter Avalos 5652940b44dSPeter Avalos 5662940b44dSPeter Avalos /** 5672940b44dSPeter Avalos * \brief Initialize .lzma decoder (legacy file format) 5682940b44dSPeter Avalos * 569*46a2189dSzrj * \param strm Pointer to properly prepared lzma_stream 570*46a2189dSzrj * \param memlimit Memory usage limit as bytes. Use UINT64_MAX 571*46a2189dSzrj * to effectively disable the limiter. liblzma 572*46a2189dSzrj * 5.2.3 and earlier don't allow 0 here and return 573*46a2189dSzrj * LZMA_PROG_ERROR; later versions treat 0 as if 1 574*46a2189dSzrj * had been specified. 575*46a2189dSzrj * 5762940b44dSPeter Avalos * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. 577*46a2189dSzrj * There is no need to use LZMA_FINISH, but it's allowed because it may 578*46a2189dSzrj * simplify certain types of applications. 5792940b44dSPeter Avalos * 5802940b44dSPeter Avalos * \return - LZMA_OK 5812940b44dSPeter Avalos * - LZMA_MEM_ERROR 5822940b44dSPeter Avalos * - LZMA_PROG_ERROR 5832940b44dSPeter Avalos */ 5842940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_alone_decoder( 5852940b44dSPeter Avalos lzma_stream *strm, uint64_t memlimit) 5862940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 5872940b44dSPeter Avalos 5882940b44dSPeter Avalos 5892940b44dSPeter Avalos /** 5902940b44dSPeter Avalos * \brief Single-call .xz Stream decoder 5912940b44dSPeter Avalos * 5922940b44dSPeter Avalos * \param memlimit Pointer to how much memory the decoder is allowed 5932940b44dSPeter Avalos * to allocate. The value pointed by this pointer is 5942940b44dSPeter Avalos * modified if and only if LZMA_MEMLIMIT_ERROR is 5952940b44dSPeter Avalos * returned. 5962940b44dSPeter Avalos * \param flags Bitwise-or of zero or more of the decoder flags: 5972940b44dSPeter Avalos * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, 5982940b44dSPeter Avalos * LZMA_CONCATENATED. Note that LZMA_TELL_ANY_CHECK 5992940b44dSPeter Avalos * is not allowed and will return LZMA_PROG_ERROR. 6002940b44dSPeter Avalos * \param allocator lzma_allocator for custom allocator functions. 6012940b44dSPeter Avalos * Set to NULL to use malloc() and free(). 6022940b44dSPeter Avalos * \param in Beginning of the input buffer 6032940b44dSPeter Avalos * \param in_pos The next byte will be read from in[*in_pos]. 6042940b44dSPeter Avalos * *in_pos is updated only if decoding succeeds. 6052940b44dSPeter Avalos * \param in_size Size of the input buffer; the first byte that 6062940b44dSPeter Avalos * won't be read is in[in_size]. 6072940b44dSPeter Avalos * \param out Beginning of the output buffer 6082940b44dSPeter Avalos * \param out_pos The next byte will be written to out[*out_pos]. 6092940b44dSPeter Avalos * *out_pos is updated only if decoding succeeds. 6102940b44dSPeter Avalos * \param out_size Size of the out buffer; the first byte into 6112940b44dSPeter Avalos * which no data is written to is out[out_size]. 6122940b44dSPeter Avalos * 6132940b44dSPeter Avalos * \return - LZMA_OK: Decoding was successful. 6142940b44dSPeter Avalos * - LZMA_FORMAT_ERROR 6152940b44dSPeter Avalos * - LZMA_OPTIONS_ERROR 6162940b44dSPeter Avalos * - LZMA_DATA_ERROR 6172940b44dSPeter Avalos * - LZMA_NO_CHECK: This can be returned only if using 6182940b44dSPeter Avalos * the LZMA_TELL_NO_CHECK flag. 6192940b44dSPeter Avalos * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using 6202940b44dSPeter Avalos * the LZMA_TELL_UNSUPPORTED_CHECK flag. 6212940b44dSPeter Avalos * - LZMA_MEM_ERROR 6222940b44dSPeter Avalos * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. 6232940b44dSPeter Avalos * The minimum required memlimit value was stored to *memlimit. 6242940b44dSPeter Avalos * - LZMA_BUF_ERROR: Output buffer was too small. 6252940b44dSPeter Avalos * - LZMA_PROG_ERROR 6262940b44dSPeter Avalos */ 6272940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_stream_buffer_decode( 62815ab8c86SJohn Marino uint64_t *memlimit, uint32_t flags, 62915ab8c86SJohn Marino const lzma_allocator *allocator, 6302940b44dSPeter Avalos const uint8_t *in, size_t *in_pos, size_t in_size, 6312940b44dSPeter Avalos uint8_t *out, size_t *out_pos, size_t out_size) 6322940b44dSPeter Avalos lzma_nothrow lzma_attr_warn_unused_result; 633