2 * \file lzma/container.h
9 * This file has been put into the public domain.
10 * You can do whatever you want with this file.
12 * See ../lzma.h for information about liblzma as a whole.
15 #ifndef LZMA_H_INTERNAL
16 # error Never include this file directly. Use <lzma.h> instead.
25 * \brief Default compression preset
27 * It's not straightforward to recommend a default preset, because in some
28 * cases keeping the resource usage relatively low is more important that
29 * getting the maximum compression ratio.
31 #define LZMA_PRESET_DEFAULT UINT32_C(6)
35 * \brief Mask for preset level
37 * This is useful only if you need to extract the level from the preset
38 * variable. That should be rare.
40 #define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F)
46 * Currently only one flag is defined.
50 * \brief Extreme compression preset
52 * This flag modifies the preset to make the encoding significantly slower
53 * while improving the compression ratio only marginally. This is useful
54 * when you don't mind wasting time to get as small result as possible.
56 * This flag doesn't affect the memory usage requirements of the decoder (at
57 * least not significantly). The memory usage of the encoder may be increased
58 * a little but only at the lowest preset levels (0-4 or so).
60 #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31)
64 * \brief Calculate rough memory usage of easy encoder
66 * This function is a wrapper for lzma_raw_encoder_memusage().
68 * \param preset Compression preset (level and possible flags)
70 extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
75 * \brief Calculate rough decoder memory usage of a preset
77 * This function is a wrapper for lzma_raw_decoder_memusage().
79 * \param preset Compression preset (level and possible flags)
81 extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
86 * \brief Initialize .xz Stream encoder using a preset number
88 * This function is intended for those who just want to use the basic features
89 * if liblzma (that is, most developers out there).
91 * \param strm Pointer to lzma_stream that is at least initialized
92 * with LZMA_STREAM_INIT.
93 * \param preset Compression preset to use. A preset consist of level
94 * number and zero or more flags. Usually flags aren't
95 * used, so preset is simply a number [0, 9] which match
96 * the options -0 .. -9 of the xz command line tool.
97 * Additional flags can be be set using bitwise-or with
98 * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.
99 * \param check Integrity check type to use. See check.h for available
100 * checks. If you are unsure, use LZMA_CHECK_CRC32.
102 * \return - LZMA_OK: Initialization succeeded. Use lzma_code() to
104 * - LZMA_MEM_ERROR: Memory allocation failed. All memory
105 * previously allocated for *strm is now freed.
106 * - LZMA_OPTIONS_ERROR: The given compression level is not
107 * supported by this build of liblzma.
108 * - LZMA_UNSUPPORTED_CHECK: The given check type is not
109 * supported by this liblzma build.
110 * - LZMA_PROG_ERROR: One or more of the parameters have values
111 * that will never be valid. For example, strm == NULL.
113 * If initialization succeeds, use lzma_code() to do the actual encoding.
114 * Valid values for `action' (the second argument of lzma_code()) are
115 * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
116 * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
118 extern LZMA_API(lzma_ret) lzma_easy_encoder(
119 lzma_stream *strm, uint32_t preset, lzma_check check)
120 lzma_attr_warn_unused_result;
124 * \brief Single-call .xz Stream encoding using a preset number
126 * The maximum required output buffer size can be calculated with
127 * lzma_stream_buffer_bound().
129 * \param preset Compression preset to use. See the description
130 * in lzma_easy_encoder().
131 * \param check Type of the integrity check to calculate from
133 * \param allocator lzma_allocator for custom allocator functions.
134 * Set to NULL to use malloc() and free().
135 * \param in Beginning of the input buffer
136 * \param in_size Size of the input buffer
137 * \param out Beginning of the output buffer
138 * \param out_pos The next byte will be written to out[*out_pos].
139 * *out_pos is updated only if encoding succeeds.
140 * \param out_size Size of the out buffer; the first byte into
141 * which no data is written to is out[out_size].
143 * \return - LZMA_OK: Encoding was successful.
144 * - LZMA_BUF_ERROR: Not enough output buffer space.
145 * - LZMA_OPTIONS_ERROR
150 extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(
151 uint32_t preset, lzma_check check,
152 lzma_allocator *allocator, const uint8_t *in, size_t in_size,
153 uint8_t *out, size_t *out_pos, size_t out_size);
157 * \brief Initialize .xz Stream encoder using a custom filter chain
159 * \param strm Pointer to properly prepared lzma_stream
160 * \param filters Array of filters. This must be terminated with
161 * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for
163 * \param check Type of the integrity check to calculate from
166 * \return - LZMA_OK: Initialization was successful.
168 * - LZMA_OPTIONS_ERROR
171 extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
172 const lzma_filter *filters, lzma_check check)
173 lzma_attr_warn_unused_result;
177 * \brief Initialize .lzma encoder (legacy file format)
179 * The .lzma format is sometimes called the LZMA_Alone format, which is the
180 * reason for the name of this function. The .lzma format supports only the
181 * LZMA1 filter. There is no support for integrity checks like CRC32.
183 * Use this function if and only if you need to create files readable by
184 * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format
185 * is strongly recommended.
187 * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH.
188 * No kind of flushing is supported, because the file format doesn't make
193 * - LZMA_OPTIONS_ERROR
196 extern LZMA_API(lzma_ret) lzma_alone_encoder(
197 lzma_stream *strm, const lzma_options_lzma *options)
198 lzma_attr_warn_unused_result;
202 * \brief Calculate output buffer size for single-call Stream encoder
204 * When trying to compress uncompressible data, the encoded size will be
205 * slightly bigger than the input data. This function calculates how much
206 * output buffer space is required to be sure that lzma_stream_buffer_encode()
207 * doesn't return LZMA_BUF_ERROR.
209 * The calculated value is not exact, but it is guaranteed to be big enough.
210 * The actual maximum output space required may be slightly smaller (up to
211 * about 100 bytes). This should not be a problem in practice.
213 * If the calculated maximum size doesn't fit into size_t or would make the
214 * Stream grow past LZMA_VLI_MAX (which should never happen in practice),
215 * zero is returned to indicate the error.
217 * \note The limit calculated by this function applies only to
218 * single-call encoding. Multi-call encoding may (and probably
219 * will) have larger maximum expansion when encoding
220 * uncompressible data. Currently there is no function to
221 * calculate the maximum expansion of multi-call encoding.
223 extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size);
227 * \brief Single-call Stream encoder
229 * \param filters Array of filters. This must be terminated with
230 * filters[n].id = LZMA_VLI_UNKNOWN. See filter.h
231 * for more information.
232 * \param check Type of the integrity check to calculate from
234 * \param allocator lzma_allocator for custom allocator functions.
235 * Set to NULL to use malloc() and free().
236 * \param in Beginning of the input buffer
237 * \param in_size Size of the input buffer
238 * \param out Beginning of the output buffer
239 * \param out_pos The next byte will be written to out[*out_pos].
240 * *out_pos is updated only if encoding succeeds.
241 * \param out_size Size of the out buffer; the first byte into
242 * which no data is written to is out[out_size].
244 * \return - LZMA_OK: Encoding was successful.
245 * - LZMA_BUF_ERROR: Not enough output buffer space.
246 * - LZMA_OPTIONS_ERROR
251 extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
252 lzma_filter *filters, lzma_check check,
253 lzma_allocator *allocator, const uint8_t *in, size_t in_size,
254 uint8_t *out, size_t *out_pos, size_t out_size)
255 lzma_attr_warn_unused_result;
263 * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream
264 * being decoded has no integrity check. Note that when used with
265 * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK
266 * if LZMA_TELL_NO_CHECK is used.
268 #define LZMA_TELL_NO_CHECK UINT32_C(0x01)
272 * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input
273 * stream has an integrity check, but the type of the integrity check is not
274 * supported by this liblzma version or build. Such files can still be
275 * decoded, but the integrity check cannot be verified.
277 #define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02)
281 * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type
282 * of the integrity check is known. The type can then be got with
285 #define LZMA_TELL_ANY_CHECK UINT32_C(0x04)
289 * This flag enables decoding of concatenated files with file formats that
290 * allow concatenating compressed files as is. From the formats currently
291 * supported by liblzma, only the .xz format allows concatenated files.
292 * Concatenated files are not allowed with the legacy .lzma format.
294 * This flag also affects the usage of the `action' argument for lzma_code().
295 * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END
296 * unless LZMA_FINISH is used as `action'. Thus, the application has to set
297 * LZMA_FINISH in the same way as it does when encoding.
299 * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH
300 * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
302 #define LZMA_CONCATENATED UINT32_C(0x08)
306 * \brief Initialize .xz Stream decoder
308 * \param strm Pointer to properly prepared lzma_stream
309 * \param memlimit Rough memory usage limit as bytes
310 * \param flags Bitwise-or of zero or more of the decoder flags:
311 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
312 * LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED
314 * \return - LZMA_OK: Initialization was successful.
315 * - LZMA_MEM_ERROR: Cannot allocate memory.
316 * - LZMA_OPTIONS_ERROR: Unsupported flags
318 extern LZMA_API(lzma_ret) lzma_stream_decoder(
319 lzma_stream *strm, uint64_t memlimit, uint32_t flags)
320 lzma_attr_warn_unused_result;
324 * \brief Decode .xz Streams and .lzma files with autodetection
326 * This decoder autodetects between the .xz and .lzma file formats, and
327 * calls lzma_stream_decoder() or lzma_alone_decoder() once the type
328 * of the input file has been detected.
330 * \param strm Pointer to properly prepared lzma_stream
331 * \param memlimit Rough memory usage limit as bytes
332 * \param flags Bitwise-or of flags, or zero for no flags.
334 * \return - LZMA_OK: Initialization was successful.
335 * - LZMA_MEM_ERROR: Cannot allocate memory.
336 * - LZMA_OPTIONS_ERROR: Unsupported flags
338 extern LZMA_API(lzma_ret) lzma_auto_decoder(
339 lzma_stream *strm, uint64_t memlimit, uint32_t flags)
340 lzma_attr_warn_unused_result;
344 * \brief Initialize .lzma decoder (legacy file format)
346 * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
347 * There is no need to use LZMA_FINISH, but allowing it may simplify
348 * certain types of applications.
353 extern LZMA_API(lzma_ret) lzma_alone_decoder(
354 lzma_stream *strm, uint64_t memlimit)
355 lzma_attr_warn_unused_result;
359 * \brief Single-call .xz Stream decoder
361 * \param memlimit Pointer to how much memory the decoder is allowed
362 * to allocate. The value pointed by this pointer is
363 * modified if and only if LZMA_MEMLIMIT_ERROR is
365 * \param flags Bitwise-or of zero or more of the decoder flags:
366 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
367 * LZMA_CONCATENATED. Note that LZMA_TELL_ANY_CHECK
368 * is not allowed and will return LZMA_PROG_ERROR.
369 * \param allocator lzma_allocator for custom allocator functions.
370 * Set to NULL to use malloc() and free().
371 * \param in Beginning of the input buffer
372 * \param in_pos The next byte will be read from in[*in_pos].
373 * *in_pos is updated only if decoding succeeds.
374 * \param in_size Size of the input buffer; the first byte that
375 * won't be read is in[in_size].
376 * \param out Beginning of the output buffer
377 * \param out_pos The next byte will be written to out[*out_pos].
378 * *out_pos is updated only if encoding succeeds.
379 * \param out_size Size of the out buffer; the first byte into
380 * which no data is written to is out[out_size].
382 * \return - LZMA_OK: Decoding was successful.
383 * - LZMA_FORMAT_ERROR
384 * - LZMA_OPTIONS_ERROR
386 * - LZMA_NO_CHECK: This can be returned only if using
387 * the LZMA_TELL_NO_CHECK flag.
388 * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using
389 * the LZMA_TELL_UNSUPPORTED_CHECK flag.
391 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
392 * The minimum required memlimit value was stored to *memlimit.
393 * - LZMA_BUF_ERROR: Output buffer was too small.
396 extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
397 uint64_t *memlimit, uint32_t flags, lzma_allocator *allocator,
398 const uint8_t *in, size_t *in_pos, size_t in_size,
399 uint8_t *out, size_t *out_pos, size_t out_size)
400 lzma_attr_warn_unused_result;