jpayne@69
|
1 /* SPDX-License-Identifier: 0BSD */
|
jpayne@69
|
2
|
jpayne@69
|
3 /**
|
jpayne@69
|
4 * \file lzma/container.h
|
jpayne@69
|
5 * \brief File formats
|
jpayne@69
|
6 * \note Never include this file directly. Use <lzma.h> instead.
|
jpayne@69
|
7 */
|
jpayne@69
|
8
|
jpayne@69
|
9 /*
|
jpayne@69
|
10 * Author: Lasse Collin
|
jpayne@69
|
11 */
|
jpayne@69
|
12
|
jpayne@69
|
13 #ifndef LZMA_H_INTERNAL
|
jpayne@69
|
14 # error Never include this file directly. Use <lzma.h> instead.
|
jpayne@69
|
15 #endif
|
jpayne@69
|
16
|
jpayne@69
|
17
|
jpayne@69
|
18 /************
|
jpayne@69
|
19 * Encoding *
|
jpayne@69
|
20 ************/
|
jpayne@69
|
21
|
jpayne@69
|
22 /**
|
jpayne@69
|
23 * \brief Default compression preset
|
jpayne@69
|
24 *
|
jpayne@69
|
25 * It's not straightforward to recommend a default preset, because in some
|
jpayne@69
|
26 * cases keeping the resource usage relatively low is more important that
|
jpayne@69
|
27 * getting the maximum compression ratio.
|
jpayne@69
|
28 */
|
jpayne@69
|
29 #define LZMA_PRESET_DEFAULT UINT32_C(6)
|
jpayne@69
|
30
|
jpayne@69
|
31
|
jpayne@69
|
32 /**
|
jpayne@69
|
33 * \brief Mask for preset level
|
jpayne@69
|
34 *
|
jpayne@69
|
35 * This is useful only if you need to extract the level from the preset
|
jpayne@69
|
36 * variable. That should be rare.
|
jpayne@69
|
37 */
|
jpayne@69
|
38 #define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F)
|
jpayne@69
|
39
|
jpayne@69
|
40
|
jpayne@69
|
41 /*
|
jpayne@69
|
42 * Preset flags
|
jpayne@69
|
43 *
|
jpayne@69
|
44 * Currently only one flag is defined.
|
jpayne@69
|
45 */
|
jpayne@69
|
46
|
jpayne@69
|
47 /**
|
jpayne@69
|
48 * \brief Extreme compression preset
|
jpayne@69
|
49 *
|
jpayne@69
|
50 * This flag modifies the preset to make the encoding significantly slower
|
jpayne@69
|
51 * while improving the compression ratio only marginally. This is useful
|
jpayne@69
|
52 * when you don't mind spending time to get as small result as possible.
|
jpayne@69
|
53 *
|
jpayne@69
|
54 * This flag doesn't affect the memory usage requirements of the decoder (at
|
jpayne@69
|
55 * least not significantly). The memory usage of the encoder may be increased
|
jpayne@69
|
56 * a little but only at the lowest preset levels (0-3).
|
jpayne@69
|
57 */
|
jpayne@69
|
58 #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31)
|
jpayne@69
|
59
|
jpayne@69
|
60
|
jpayne@69
|
61 /**
|
jpayne@69
|
62 * \brief Multithreading options
|
jpayne@69
|
63 */
|
jpayne@69
|
64 typedef struct {
|
jpayne@69
|
65 /**
|
jpayne@69
|
66 * \brief Flags
|
jpayne@69
|
67 *
|
jpayne@69
|
68 * Set this to zero if no flags are wanted.
|
jpayne@69
|
69 *
|
jpayne@69
|
70 * Encoder: No flags are currently supported.
|
jpayne@69
|
71 *
|
jpayne@69
|
72 * Decoder: Bitwise-or of zero or more of the decoder flags:
|
jpayne@69
|
73 * - LZMA_TELL_NO_CHECK
|
jpayne@69
|
74 * - LZMA_TELL_UNSUPPORTED_CHECK
|
jpayne@69
|
75 * - LZMA_TELL_ANY_CHECK
|
jpayne@69
|
76 * - LZMA_IGNORE_CHECK
|
jpayne@69
|
77 * - LZMA_CONCATENATED
|
jpayne@69
|
78 * - LZMA_FAIL_FAST
|
jpayne@69
|
79 */
|
jpayne@69
|
80 uint32_t flags;
|
jpayne@69
|
81
|
jpayne@69
|
82 /**
|
jpayne@69
|
83 * \brief Number of worker threads to use
|
jpayne@69
|
84 */
|
jpayne@69
|
85 uint32_t threads;
|
jpayne@69
|
86
|
jpayne@69
|
87 /**
|
jpayne@69
|
88 * \brief Encoder only: Maximum uncompressed size of a Block
|
jpayne@69
|
89 *
|
jpayne@69
|
90 * The encoder will start a new .xz Block every block_size bytes.
|
jpayne@69
|
91 * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code()
|
jpayne@69
|
92 * the caller may tell liblzma to start a new Block earlier.
|
jpayne@69
|
93 *
|
jpayne@69
|
94 * With LZMA2, a recommended block size is 2-4 times the LZMA2
|
jpayne@69
|
95 * dictionary size. With very small dictionaries, it is recommended
|
jpayne@69
|
96 * to use at least 1 MiB block size for good compression ratio, even
|
jpayne@69
|
97 * if this is more than four times the dictionary size. Note that
|
jpayne@69
|
98 * these are only recommendations for typical use cases; feel free
|
jpayne@69
|
99 * to use other values. Just keep in mind that using a block size
|
jpayne@69
|
100 * less than the LZMA2 dictionary size is waste of RAM.
|
jpayne@69
|
101 *
|
jpayne@69
|
102 * Set this to 0 to let liblzma choose the block size depending
|
jpayne@69
|
103 * on the compression options. For LZMA2 it will be 3*dict_size
|
jpayne@69
|
104 * or 1 MiB, whichever is more.
|
jpayne@69
|
105 *
|
jpayne@69
|
106 * For each thread, about 3 * block_size bytes of memory will be
|
jpayne@69
|
107 * allocated. This may change in later liblzma versions. If so,
|
jpayne@69
|
108 * the memory usage will probably be reduced, not increased.
|
jpayne@69
|
109 */
|
jpayne@69
|
110 uint64_t block_size;
|
jpayne@69
|
111
|
jpayne@69
|
112 /**
|
jpayne@69
|
113 * \brief Timeout to allow lzma_code() to return early
|
jpayne@69
|
114 *
|
jpayne@69
|
115 * Multithreading can make liblzma consume input and produce
|
jpayne@69
|
116 * output in a very bursty way: it may first read a lot of input
|
jpayne@69
|
117 * to fill internal buffers, then no input or output occurs for
|
jpayne@69
|
118 * a while.
|
jpayne@69
|
119 *
|
jpayne@69
|
120 * In single-threaded mode, lzma_code() won't return until it has
|
jpayne@69
|
121 * either consumed all the input or filled the output buffer. If
|
jpayne@69
|
122 * this is done in multithreaded mode, it may cause a call
|
jpayne@69
|
123 * lzma_code() to take even tens of seconds, which isn't acceptable
|
jpayne@69
|
124 * in all applications.
|
jpayne@69
|
125 *
|
jpayne@69
|
126 * To avoid very long blocking times in lzma_code(), a timeout
|
jpayne@69
|
127 * (in milliseconds) may be set here. If lzma_code() would block
|
jpayne@69
|
128 * longer than this number of milliseconds, it will return with
|
jpayne@69
|
129 * LZMA_OK. Reasonable values are 100 ms or more. The xz command
|
jpayne@69
|
130 * line tool uses 300 ms.
|
jpayne@69
|
131 *
|
jpayne@69
|
132 * If long blocking times are acceptable, set timeout to a special
|
jpayne@69
|
133 * value of 0. This will disable the timeout mechanism and will make
|
jpayne@69
|
134 * lzma_code() block until all the input is consumed or the output
|
jpayne@69
|
135 * buffer has been filled.
|
jpayne@69
|
136 *
|
jpayne@69
|
137 * \note Even with a timeout, lzma_code() might sometimes take
|
jpayne@69
|
138 * a long time to return. No timing guarantees are made.
|
jpayne@69
|
139 */
|
jpayne@69
|
140 uint32_t timeout;
|
jpayne@69
|
141
|
jpayne@69
|
142 /**
|
jpayne@69
|
143 * \brief Encoder only: Compression preset
|
jpayne@69
|
144 *
|
jpayne@69
|
145 * The preset is set just like with lzma_easy_encoder().
|
jpayne@69
|
146 * The preset is ignored if filters below is non-NULL.
|
jpayne@69
|
147 */
|
jpayne@69
|
148 uint32_t preset;
|
jpayne@69
|
149
|
jpayne@69
|
150 /**
|
jpayne@69
|
151 * \brief Encoder only: Filter chain (alternative to a preset)
|
jpayne@69
|
152 *
|
jpayne@69
|
153 * If this is NULL, the preset above is used. Otherwise the preset
|
jpayne@69
|
154 * is ignored and the filter chain specified here is used.
|
jpayne@69
|
155 */
|
jpayne@69
|
156 const lzma_filter *filters;
|
jpayne@69
|
157
|
jpayne@69
|
158 /**
|
jpayne@69
|
159 * \brief Encoder only: Integrity check type
|
jpayne@69
|
160 *
|
jpayne@69
|
161 * See check.h for available checks. The xz command line tool
|
jpayne@69
|
162 * defaults to LZMA_CHECK_CRC64, which is a good choice if you
|
jpayne@69
|
163 * are unsure.
|
jpayne@69
|
164 */
|
jpayne@69
|
165 lzma_check check;
|
jpayne@69
|
166
|
jpayne@69
|
167 /*
|
jpayne@69
|
168 * Reserved space to allow possible future extensions without
|
jpayne@69
|
169 * breaking the ABI. You should not touch these, because the names
|
jpayne@69
|
170 * of these variables may change. These are and will never be used
|
jpayne@69
|
171 * with the currently supported options, so it is safe to leave these
|
jpayne@69
|
172 * uninitialized.
|
jpayne@69
|
173 */
|
jpayne@69
|
174 /** \private Reserved member. */
|
jpayne@69
|
175 lzma_reserved_enum reserved_enum1;
|
jpayne@69
|
176
|
jpayne@69
|
177 /** \private Reserved member. */
|
jpayne@69
|
178 lzma_reserved_enum reserved_enum2;
|
jpayne@69
|
179
|
jpayne@69
|
180 /** \private Reserved member. */
|
jpayne@69
|
181 lzma_reserved_enum reserved_enum3;
|
jpayne@69
|
182
|
jpayne@69
|
183 /** \private Reserved member. */
|
jpayne@69
|
184 uint32_t reserved_int1;
|
jpayne@69
|
185
|
jpayne@69
|
186 /** \private Reserved member. */
|
jpayne@69
|
187 uint32_t reserved_int2;
|
jpayne@69
|
188
|
jpayne@69
|
189 /** \private Reserved member. */
|
jpayne@69
|
190 uint32_t reserved_int3;
|
jpayne@69
|
191
|
jpayne@69
|
192 /** \private Reserved member. */
|
jpayne@69
|
193 uint32_t reserved_int4;
|
jpayne@69
|
194
|
jpayne@69
|
195 /**
|
jpayne@69
|
196 * \brief Memory usage limit to reduce the number of threads
|
jpayne@69
|
197 *
|
jpayne@69
|
198 * Encoder: Ignored.
|
jpayne@69
|
199 *
|
jpayne@69
|
200 * Decoder:
|
jpayne@69
|
201 *
|
jpayne@69
|
202 * If the number of threads has been set so high that more than
|
jpayne@69
|
203 * memlimit_threading bytes of memory would be needed, the number
|
jpayne@69
|
204 * of threads will be reduced so that the memory usage will not exceed
|
jpayne@69
|
205 * memlimit_threading bytes. However, if memlimit_threading cannot
|
jpayne@69
|
206 * be met even in single-threaded mode, then decoding will continue
|
jpayne@69
|
207 * in single-threaded mode and memlimit_threading may be exceeded
|
jpayne@69
|
208 * even by a large amount. That is, memlimit_threading will never make
|
jpayne@69
|
209 * lzma_code() return LZMA_MEMLIMIT_ERROR. To truly cap the memory
|
jpayne@69
|
210 * usage, see memlimit_stop below.
|
jpayne@69
|
211 *
|
jpayne@69
|
212 * Setting memlimit_threading to UINT64_MAX or a similar huge value
|
jpayne@69
|
213 * means that liblzma is allowed to keep the whole compressed file
|
jpayne@69
|
214 * and the whole uncompressed file in memory in addition to the memory
|
jpayne@69
|
215 * needed by the decompressor data structures used by each thread!
|
jpayne@69
|
216 * In other words, a reasonable value limit must be set here or it
|
jpayne@69
|
217 * will cause problems sooner or later. If you have no idea what
|
jpayne@69
|
218 * a reasonable value could be, try lzma_physmem() / 4 as a starting
|
jpayne@69
|
219 * point. Setting this limit will never prevent decompression of
|
jpayne@69
|
220 * a file; this will only reduce the number of threads.
|
jpayne@69
|
221 *
|
jpayne@69
|
222 * If memlimit_threading is greater than memlimit_stop, then the value
|
jpayne@69
|
223 * of memlimit_stop will be used for both.
|
jpayne@69
|
224 */
|
jpayne@69
|
225 uint64_t memlimit_threading;
|
jpayne@69
|
226
|
jpayne@69
|
227 /**
|
jpayne@69
|
228 * \brief Memory usage limit that should never be exceeded
|
jpayne@69
|
229 *
|
jpayne@69
|
230 * Encoder: Ignored.
|
jpayne@69
|
231 *
|
jpayne@69
|
232 * Decoder: If decompressing will need more than this amount of
|
jpayne@69
|
233 * memory even in the single-threaded mode, then lzma_code() will
|
jpayne@69
|
234 * return LZMA_MEMLIMIT_ERROR.
|
jpayne@69
|
235 */
|
jpayne@69
|
236 uint64_t memlimit_stop;
|
jpayne@69
|
237
|
jpayne@69
|
238 /** \private Reserved member. */
|
jpayne@69
|
239 uint64_t reserved_int7;
|
jpayne@69
|
240
|
jpayne@69
|
241 /** \private Reserved member. */
|
jpayne@69
|
242 uint64_t reserved_int8;
|
jpayne@69
|
243
|
jpayne@69
|
244 /** \private Reserved member. */
|
jpayne@69
|
245 void *reserved_ptr1;
|
jpayne@69
|
246
|
jpayne@69
|
247 /** \private Reserved member. */
|
jpayne@69
|
248 void *reserved_ptr2;
|
jpayne@69
|
249
|
jpayne@69
|
250 /** \private Reserved member. */
|
jpayne@69
|
251 void *reserved_ptr3;
|
jpayne@69
|
252
|
jpayne@69
|
253 /** \private Reserved member. */
|
jpayne@69
|
254 void *reserved_ptr4;
|
jpayne@69
|
255
|
jpayne@69
|
256 } lzma_mt;
|
jpayne@69
|
257
|
jpayne@69
|
258
|
jpayne@69
|
259 /**
|
jpayne@69
|
260 * \brief Calculate approximate memory usage of easy encoder
|
jpayne@69
|
261 *
|
jpayne@69
|
262 * This function is a wrapper for lzma_raw_encoder_memusage().
|
jpayne@69
|
263 *
|
jpayne@69
|
264 * \param preset Compression preset (level and possible flags)
|
jpayne@69
|
265 *
|
jpayne@69
|
266 * \return Number of bytes of memory required for the given
|
jpayne@69
|
267 * preset when encoding or UINT64_MAX on error.
|
jpayne@69
|
268 */
|
jpayne@69
|
269 extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
|
jpayne@69
|
270 lzma_nothrow lzma_attr_pure;
|
jpayne@69
|
271
|
jpayne@69
|
272
|
jpayne@69
|
273 /**
|
jpayne@69
|
274 * \brief Calculate approximate decoder memory usage of a preset
|
jpayne@69
|
275 *
|
jpayne@69
|
276 * This function is a wrapper for lzma_raw_decoder_memusage().
|
jpayne@69
|
277 *
|
jpayne@69
|
278 * \param preset Compression preset (level and possible flags)
|
jpayne@69
|
279 *
|
jpayne@69
|
280 * \return Number of bytes of memory required to decompress a file
|
jpayne@69
|
281 * that was compressed using the given preset or UINT64_MAX
|
jpayne@69
|
282 * on error.
|
jpayne@69
|
283 */
|
jpayne@69
|
284 extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
|
jpayne@69
|
285 lzma_nothrow lzma_attr_pure;
|
jpayne@69
|
286
|
jpayne@69
|
287
|
jpayne@69
|
288 /**
|
jpayne@69
|
289 * \brief Initialize .xz Stream encoder using a preset number
|
jpayne@69
|
290 *
|
jpayne@69
|
291 * This function is intended for those who just want to use the basic features
|
jpayne@69
|
292 * of liblzma (that is, most developers out there).
|
jpayne@69
|
293 *
|
jpayne@69
|
294 * If initialization fails (return value is not LZMA_OK), all the memory
|
jpayne@69
|
295 * allocated for *strm by liblzma is always freed. Thus, there is no need
|
jpayne@69
|
296 * to call lzma_end() after failed initialization.
|
jpayne@69
|
297 *
|
jpayne@69
|
298 * If initialization succeeds, use lzma_code() to do the actual encoding.
|
jpayne@69
|
299 * Valid values for 'action' (the second argument of lzma_code()) are
|
jpayne@69
|
300 * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
|
jpayne@69
|
301 * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
|
jpayne@69
|
302 *
|
jpayne@69
|
303 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
304 * with LZMA_STREAM_INIT.
|
jpayne@69
|
305 * \param preset Compression preset to use. A preset consist of level
|
jpayne@69
|
306 * number and zero or more flags. Usually flags aren't
|
jpayne@69
|
307 * used, so preset is simply a number [0, 9] which match
|
jpayne@69
|
308 * the options -0 ... -9 of the xz command line tool.
|
jpayne@69
|
309 * Additional flags can be set using bitwise-or with
|
jpayne@69
|
310 * the preset level number, e.g. 6 | LZMA_PRESET_EXTREME.
|
jpayne@69
|
311 * \param check Integrity check type to use. See check.h for available
|
jpayne@69
|
312 * checks. The xz command line tool defaults to
|
jpayne@69
|
313 * LZMA_CHECK_CRC64, which is a good choice if you are
|
jpayne@69
|
314 * unsure. LZMA_CHECK_CRC32 is good too as long as the
|
jpayne@69
|
315 * uncompressed file is not many gigabytes.
|
jpayne@69
|
316 *
|
jpayne@69
|
317 * \return Possible lzma_ret values:
|
jpayne@69
|
318 * - LZMA_OK: Initialization succeeded. Use lzma_code() to
|
jpayne@69
|
319 * encode your data.
|
jpayne@69
|
320 * - LZMA_MEM_ERROR: Memory allocation failed.
|
jpayne@69
|
321 * - LZMA_OPTIONS_ERROR: The given compression preset is not
|
jpayne@69
|
322 * supported by this build of liblzma.
|
jpayne@69
|
323 * - LZMA_UNSUPPORTED_CHECK: The given check type is not
|
jpayne@69
|
324 * supported by this liblzma build.
|
jpayne@69
|
325 * - LZMA_PROG_ERROR: One or more of the parameters have values
|
jpayne@69
|
326 * that will never be valid. For example, strm == NULL.
|
jpayne@69
|
327 */
|
jpayne@69
|
328 extern LZMA_API(lzma_ret) lzma_easy_encoder(
|
jpayne@69
|
329 lzma_stream *strm, uint32_t preset, lzma_check check)
|
jpayne@69
|
330 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
331
|
jpayne@69
|
332
|
jpayne@69
|
333 /**
|
jpayne@69
|
334 * \brief Single-call .xz Stream encoding using a preset number
|
jpayne@69
|
335 *
|
jpayne@69
|
336 * The maximum required output buffer size can be calculated with
|
jpayne@69
|
337 * lzma_stream_buffer_bound().
|
jpayne@69
|
338 *
|
jpayne@69
|
339 * \param preset Compression preset to use. See the description
|
jpayne@69
|
340 * in lzma_easy_encoder().
|
jpayne@69
|
341 * \param check Type of the integrity check to calculate from
|
jpayne@69
|
342 * uncompressed data.
|
jpayne@69
|
343 * \param allocator lzma_allocator for custom allocator functions.
|
jpayne@69
|
344 * Set to NULL to use malloc() and free().
|
jpayne@69
|
345 * \param in Beginning of the input buffer
|
jpayne@69
|
346 * \param in_size Size of the input buffer
|
jpayne@69
|
347 * \param[out] out Beginning of the output buffer
|
jpayne@69
|
348 * \param[out] out_pos The next byte will be written to out[*out_pos].
|
jpayne@69
|
349 * *out_pos is updated only if encoding succeeds.
|
jpayne@69
|
350 * \param out_size Size of the out buffer; the first byte into
|
jpayne@69
|
351 * which no data is written to is out[out_size].
|
jpayne@69
|
352 *
|
jpayne@69
|
353 * \return Possible lzma_ret values:
|
jpayne@69
|
354 * - LZMA_OK: Encoding was successful.
|
jpayne@69
|
355 * - LZMA_BUF_ERROR: Not enough output buffer space.
|
jpayne@69
|
356 * - LZMA_UNSUPPORTED_CHECK
|
jpayne@69
|
357 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
358 * - LZMA_MEM_ERROR
|
jpayne@69
|
359 * - LZMA_DATA_ERROR
|
jpayne@69
|
360 * - LZMA_PROG_ERROR
|
jpayne@69
|
361 */
|
jpayne@69
|
362 extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(
|
jpayne@69
|
363 uint32_t preset, lzma_check check,
|
jpayne@69
|
364 const lzma_allocator *allocator,
|
jpayne@69
|
365 const uint8_t *in, size_t in_size,
|
jpayne@69
|
366 uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
|
jpayne@69
|
367
|
jpayne@69
|
368
|
jpayne@69
|
369 /**
|
jpayne@69
|
370 * \brief Initialize .xz Stream encoder using a custom filter chain
|
jpayne@69
|
371 *
|
jpayne@69
|
372 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
373 * with LZMA_STREAM_INIT.
|
jpayne@69
|
374 * \param filters Array of filters terminated with
|
jpayne@69
|
375 * .id == LZMA_VLI_UNKNOWN. See filters.h for more
|
jpayne@69
|
376 * information.
|
jpayne@69
|
377 * \param check Type of the integrity check to calculate from
|
jpayne@69
|
378 * uncompressed data.
|
jpayne@69
|
379 *
|
jpayne@69
|
380 * \return Possible lzma_ret values:
|
jpayne@69
|
381 * - LZMA_OK: Initialization was successful.
|
jpayne@69
|
382 * - LZMA_MEM_ERROR
|
jpayne@69
|
383 * - LZMA_UNSUPPORTED_CHECK
|
jpayne@69
|
384 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
385 * - LZMA_PROG_ERROR
|
jpayne@69
|
386 */
|
jpayne@69
|
387 extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
|
jpayne@69
|
388 const lzma_filter *filters, lzma_check check)
|
jpayne@69
|
389 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
390
|
jpayne@69
|
391
|
jpayne@69
|
392 /**
|
jpayne@69
|
393 * \brief Calculate approximate memory usage of multithreaded .xz encoder
|
jpayne@69
|
394 *
|
jpayne@69
|
395 * Since doing the encoding in threaded mode doesn't affect the memory
|
jpayne@69
|
396 * requirements of single-threaded decompressor, you can use
|
jpayne@69
|
397 * lzma_easy_decoder_memusage(options->preset) or
|
jpayne@69
|
398 * lzma_raw_decoder_memusage(options->filters) to calculate
|
jpayne@69
|
399 * the decompressor memory requirements.
|
jpayne@69
|
400 *
|
jpayne@69
|
401 * \param options Compression options
|
jpayne@69
|
402 *
|
jpayne@69
|
403 * \return Number of bytes of memory required for encoding with the
|
jpayne@69
|
404 * given options. If an error occurs, for example due to
|
jpayne@69
|
405 * unsupported preset or filter chain, UINT64_MAX is returned.
|
jpayne@69
|
406 */
|
jpayne@69
|
407 extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage(
|
jpayne@69
|
408 const lzma_mt *options) lzma_nothrow lzma_attr_pure;
|
jpayne@69
|
409
|
jpayne@69
|
410
|
jpayne@69
|
411 /**
|
jpayne@69
|
412 * \brief Initialize multithreaded .xz Stream encoder
|
jpayne@69
|
413 *
|
jpayne@69
|
414 * This provides the functionality of lzma_easy_encoder() and
|
jpayne@69
|
415 * lzma_stream_encoder() as a single function for multithreaded use.
|
jpayne@69
|
416 *
|
jpayne@69
|
417 * The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH,
|
jpayne@69
|
418 * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be
|
jpayne@69
|
419 * added in the future.
|
jpayne@69
|
420 *
|
jpayne@69
|
421 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
422 * with LZMA_STREAM_INIT.
|
jpayne@69
|
423 * \param options Pointer to multithreaded compression options
|
jpayne@69
|
424 *
|
jpayne@69
|
425 * \return Possible lzma_ret values:
|
jpayne@69
|
426 * - LZMA_OK
|
jpayne@69
|
427 * - LZMA_MEM_ERROR
|
jpayne@69
|
428 * - LZMA_UNSUPPORTED_CHECK
|
jpayne@69
|
429 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
430 * - LZMA_PROG_ERROR
|
jpayne@69
|
431 */
|
jpayne@69
|
432 extern LZMA_API(lzma_ret) lzma_stream_encoder_mt(
|
jpayne@69
|
433 lzma_stream *strm, const lzma_mt *options)
|
jpayne@69
|
434 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
435
|
jpayne@69
|
436
|
jpayne@69
|
437 /**
|
jpayne@69
|
438 * \brief Calculate recommended Block size for multithreaded .xz encoder
|
jpayne@69
|
439 *
|
jpayne@69
|
440 * This calculates a recommended Block size for multithreaded encoding given
|
jpayne@69
|
441 * a filter chain. This is used internally by lzma_stream_encoder_mt() to
|
jpayne@69
|
442 * determine the Block size if the block_size member is not set to the
|
jpayne@69
|
443 * special value of 0 in the lzma_mt options struct.
|
jpayne@69
|
444 *
|
jpayne@69
|
445 * If one wishes to change the filters between Blocks, this function is
|
jpayne@69
|
446 * helpful to set the block_size member of the lzma_mt struct before calling
|
jpayne@69
|
447 * lzma_stream_encoder_mt(). Since the block_size member represents the
|
jpayne@69
|
448 * maximum possible Block size for the multithreaded .xz encoder, one can
|
jpayne@69
|
449 * use this function to find the maximum recommended Block size based on
|
jpayne@69
|
450 * all planned filter chains. Otherwise, the multithreaded encoder will
|
jpayne@69
|
451 * base its maximum Block size on the first filter chain used (if the
|
jpayne@69
|
452 * block_size member is not set), which may unnecessarily limit the Block
|
jpayne@69
|
453 * size for a later filter chain.
|
jpayne@69
|
454 *
|
jpayne@69
|
455 * \param filters Array of filters terminated with
|
jpayne@69
|
456 * .id == LZMA_VLI_UNKNOWN.
|
jpayne@69
|
457 *
|
jpayne@69
|
458 * \return Recommended Block size in bytes, or UINT64_MAX if
|
jpayne@69
|
459 * an error occurred.
|
jpayne@69
|
460 */
|
jpayne@69
|
461 extern LZMA_API(uint64_t) lzma_mt_block_size(const lzma_filter *filters)
|
jpayne@69
|
462 lzma_nothrow;
|
jpayne@69
|
463
|
jpayne@69
|
464
|
jpayne@69
|
465 /**
|
jpayne@69
|
466 * \brief Initialize .lzma encoder (legacy file format)
|
jpayne@69
|
467 *
|
jpayne@69
|
468 * The .lzma format is sometimes called the LZMA_Alone format, which is the
|
jpayne@69
|
469 * reason for the name of this function. The .lzma format supports only the
|
jpayne@69
|
470 * LZMA1 filter. There is no support for integrity checks like CRC32.
|
jpayne@69
|
471 *
|
jpayne@69
|
472 * Use this function if and only if you need to create files readable by
|
jpayne@69
|
473 * legacy LZMA tools such as LZMA Utils 4.32.x. Moving to the .xz format
|
jpayne@69
|
474 * is strongly recommended.
|
jpayne@69
|
475 *
|
jpayne@69
|
476 * The valid action values for lzma_code() are LZMA_RUN and LZMA_FINISH.
|
jpayne@69
|
477 * No kind of flushing is supported, because the file format doesn't make
|
jpayne@69
|
478 * it possible.
|
jpayne@69
|
479 *
|
jpayne@69
|
480 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
481 * with LZMA_STREAM_INIT.
|
jpayne@69
|
482 * \param options Pointer to encoder options
|
jpayne@69
|
483 *
|
jpayne@69
|
484 * \return Possible lzma_ret values:
|
jpayne@69
|
485 * - LZMA_OK
|
jpayne@69
|
486 * - LZMA_MEM_ERROR
|
jpayne@69
|
487 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
488 * - LZMA_PROG_ERROR
|
jpayne@69
|
489 */
|
jpayne@69
|
490 extern LZMA_API(lzma_ret) lzma_alone_encoder(
|
jpayne@69
|
491 lzma_stream *strm, const lzma_options_lzma *options)
|
jpayne@69
|
492 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
493
|
jpayne@69
|
494
|
jpayne@69
|
495 /**
|
jpayne@69
|
496 * \brief Calculate output buffer size for single-call Stream encoder
|
jpayne@69
|
497 *
|
jpayne@69
|
498 * When trying to compress incompressible data, the encoded size will be
|
jpayne@69
|
499 * slightly bigger than the input data. This function calculates how much
|
jpayne@69
|
500 * output buffer space is required to be sure that lzma_stream_buffer_encode()
|
jpayne@69
|
501 * doesn't return LZMA_BUF_ERROR.
|
jpayne@69
|
502 *
|
jpayne@69
|
503 * The calculated value is not exact, but it is guaranteed to be big enough.
|
jpayne@69
|
504 * The actual maximum output space required may be slightly smaller (up to
|
jpayne@69
|
505 * about 100 bytes). This should not be a problem in practice.
|
jpayne@69
|
506 *
|
jpayne@69
|
507 * If the calculated maximum size doesn't fit into size_t or would make the
|
jpayne@69
|
508 * Stream grow past LZMA_VLI_MAX (which should never happen in practice),
|
jpayne@69
|
509 * zero is returned to indicate the error.
|
jpayne@69
|
510 *
|
jpayne@69
|
511 * \note The limit calculated by this function applies only to
|
jpayne@69
|
512 * single-call encoding. Multi-call encoding may (and probably
|
jpayne@69
|
513 * will) have larger maximum expansion when encoding
|
jpayne@69
|
514 * incompressible data. Currently there is no function to
|
jpayne@69
|
515 * calculate the maximum expansion of multi-call encoding.
|
jpayne@69
|
516 *
|
jpayne@69
|
517 * \param uncompressed_size Size in bytes of the uncompressed
|
jpayne@69
|
518 * input data
|
jpayne@69
|
519 *
|
jpayne@69
|
520 * \return Maximum number of bytes needed to store the compressed data.
|
jpayne@69
|
521 */
|
jpayne@69
|
522 extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
|
jpayne@69
|
523 lzma_nothrow;
|
jpayne@69
|
524
|
jpayne@69
|
525
|
jpayne@69
|
526 /**
|
jpayne@69
|
527 * \brief Single-call .xz Stream encoder
|
jpayne@69
|
528 *
|
jpayne@69
|
529 * \param filters Array of filters terminated with
|
jpayne@69
|
530 * .id == LZMA_VLI_UNKNOWN. See filters.h for more
|
jpayne@69
|
531 * information.
|
jpayne@69
|
532 * \param check Type of the integrity check to calculate from
|
jpayne@69
|
533 * uncompressed data.
|
jpayne@69
|
534 * \param allocator lzma_allocator for custom allocator functions.
|
jpayne@69
|
535 * Set to NULL to use malloc() and free().
|
jpayne@69
|
536 * \param in Beginning of the input buffer
|
jpayne@69
|
537 * \param in_size Size of the input buffer
|
jpayne@69
|
538 * \param[out] out Beginning of the output buffer
|
jpayne@69
|
539 * \param[out] out_pos The next byte will be written to out[*out_pos].
|
jpayne@69
|
540 * *out_pos is updated only if encoding succeeds.
|
jpayne@69
|
541 * \param out_size Size of the out buffer; the first byte into
|
jpayne@69
|
542 * which no data is written to is out[out_size].
|
jpayne@69
|
543 *
|
jpayne@69
|
544 * \return Possible lzma_ret values:
|
jpayne@69
|
545 * - LZMA_OK: Encoding was successful.
|
jpayne@69
|
546 * - LZMA_BUF_ERROR: Not enough output buffer space.
|
jpayne@69
|
547 * - LZMA_UNSUPPORTED_CHECK
|
jpayne@69
|
548 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
549 * - LZMA_MEM_ERROR
|
jpayne@69
|
550 * - LZMA_DATA_ERROR
|
jpayne@69
|
551 * - LZMA_PROG_ERROR
|
jpayne@69
|
552 */
|
jpayne@69
|
553 extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
|
jpayne@69
|
554 lzma_filter *filters, lzma_check check,
|
jpayne@69
|
555 const lzma_allocator *allocator,
|
jpayne@69
|
556 const uint8_t *in, size_t in_size,
|
jpayne@69
|
557 uint8_t *out, size_t *out_pos, size_t out_size)
|
jpayne@69
|
558 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
559
|
jpayne@69
|
560
|
jpayne@69
|
561 /**
|
jpayne@69
|
562 * \brief MicroLZMA encoder
|
jpayne@69
|
563 *
|
jpayne@69
|
564 * The MicroLZMA format is a raw LZMA stream whose first byte (always 0x00)
|
jpayne@69
|
565 * has been replaced with bitwise-negation of the LZMA properties (lc/lp/pb).
|
jpayne@69
|
566 * This encoding ensures that the first byte of MicroLZMA stream is never
|
jpayne@69
|
567 * 0x00. There is no end of payload marker and thus the uncompressed size
|
jpayne@69
|
568 * must be stored separately. For the best error detection the dictionary
|
jpayne@69
|
569 * size should be stored separately as well but alternatively one may use
|
jpayne@69
|
570 * the uncompressed size as the dictionary size when decoding.
|
jpayne@69
|
571 *
|
jpayne@69
|
572 * With the MicroLZMA encoder, lzma_code() behaves slightly unusually.
|
jpayne@69
|
573 * The action argument must be LZMA_FINISH and the return value will never be
|
jpayne@69
|
574 * LZMA_OK. Thus the encoding is always done with a single lzma_code() after
|
jpayne@69
|
575 * the initialization. The benefit of the combination of initialization
|
jpayne@69
|
576 * function and lzma_code() is that memory allocations can be re-used for
|
jpayne@69
|
577 * better performance.
|
jpayne@69
|
578 *
|
jpayne@69
|
579 * lzma_code() will try to encode as much input as is possible to fit into
|
jpayne@69
|
580 * the given output buffer. If not all input can be encoded, the stream will
|
jpayne@69
|
581 * be finished without encoding all the input. The caller must check both
|
jpayne@69
|
582 * input and output buffer usage after lzma_code() (total_in and total_out
|
jpayne@69
|
583 * in lzma_stream can be convenient). Often lzma_code() can fill the output
|
jpayne@69
|
584 * buffer completely if there is a lot of input, but sometimes a few bytes
|
jpayne@69
|
585 * may remain unused because the next LZMA symbol would require more space.
|
jpayne@69
|
586 *
|
jpayne@69
|
587 * lzma_stream.avail_out must be at least 6. Otherwise LZMA_PROG_ERROR
|
jpayne@69
|
588 * will be returned.
|
jpayne@69
|
589 *
|
jpayne@69
|
590 * The LZMA dictionary should be reasonably low to speed up the encoder
|
jpayne@69
|
591 * re-initialization. A good value is bigger than the resulting
|
jpayne@69
|
592 * uncompressed size of most of the output chunks. For example, if output
|
jpayne@69
|
593 * size is 4 KiB, dictionary size of 32 KiB or 64 KiB is good. If the
|
jpayne@69
|
594 * data compresses extremely well, even 128 KiB may be useful.
|
jpayne@69
|
595 *
|
jpayne@69
|
596 * The MicroLZMA format and this encoder variant were made with the EROFS
|
jpayne@69
|
597 * file system in mind. This format may be convenient in other embedded
|
jpayne@69
|
598 * uses too where many small streams are needed. XZ Embedded includes a
|
jpayne@69
|
599 * decoder for this format.
|
jpayne@69
|
600 *
|
jpayne@69
|
601 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
602 * with LZMA_STREAM_INIT.
|
jpayne@69
|
603 * \param options Pointer to encoder options
|
jpayne@69
|
604 *
|
jpayne@69
|
605 * \return Possible lzma_ret values:
|
jpayne@69
|
606 * - LZMA_STREAM_END: All good. Check the amounts of input used
|
jpayne@69
|
607 * and output produced. Store the amount of input used
|
jpayne@69
|
608 * (uncompressed size) as it needs to be known to decompress
|
jpayne@69
|
609 * the data.
|
jpayne@69
|
610 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
611 * - LZMA_MEM_ERROR
|
jpayne@69
|
612 * - LZMA_PROG_ERROR: In addition to the generic reasons for this
|
jpayne@69
|
613 * error code, this may also be returned if there isn't enough
|
jpayne@69
|
614 * output space (6 bytes) to create a valid MicroLZMA stream.
|
jpayne@69
|
615 */
|
jpayne@69
|
616 extern LZMA_API(lzma_ret) lzma_microlzma_encoder(
|
jpayne@69
|
617 lzma_stream *strm, const lzma_options_lzma *options)
|
jpayne@69
|
618 lzma_nothrow;
|
jpayne@69
|
619
|
jpayne@69
|
620
|
jpayne@69
|
621 /************
|
jpayne@69
|
622 * Decoding *
|
jpayne@69
|
623 ************/
|
jpayne@69
|
624
|
jpayne@69
|
625 /**
|
jpayne@69
|
626 * This flag makes lzma_code() return LZMA_NO_CHECK if the input stream
|
jpayne@69
|
627 * being decoded has no integrity check. Note that when used with
|
jpayne@69
|
628 * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK
|
jpayne@69
|
629 * if LZMA_TELL_NO_CHECK is used.
|
jpayne@69
|
630 */
|
jpayne@69
|
631 #define LZMA_TELL_NO_CHECK UINT32_C(0x01)
|
jpayne@69
|
632
|
jpayne@69
|
633
|
jpayne@69
|
634 /**
|
jpayne@69
|
635 * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input
|
jpayne@69
|
636 * stream has an integrity check, but the type of the integrity check is not
|
jpayne@69
|
637 * supported by this liblzma version or build. Such files can still be
|
jpayne@69
|
638 * decoded, but the integrity check cannot be verified.
|
jpayne@69
|
639 */
|
jpayne@69
|
640 #define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02)
|
jpayne@69
|
641
|
jpayne@69
|
642
|
jpayne@69
|
643 /**
|
jpayne@69
|
644 * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type
|
jpayne@69
|
645 * of the integrity check is known. The type can then be got with
|
jpayne@69
|
646 * lzma_get_check().
|
jpayne@69
|
647 */
|
jpayne@69
|
648 #define LZMA_TELL_ANY_CHECK UINT32_C(0x04)
|
jpayne@69
|
649
|
jpayne@69
|
650
|
jpayne@69
|
651 /**
|
jpayne@69
|
652 * This flag makes lzma_code() not calculate and verify the integrity check
|
jpayne@69
|
653 * of the compressed data in .xz files. This means that invalid integrity
|
jpayne@69
|
654 * check values won't be detected and LZMA_DATA_ERROR won't be returned in
|
jpayne@69
|
655 * such cases.
|
jpayne@69
|
656 *
|
jpayne@69
|
657 * This flag only affects the checks of the compressed data itself; the CRC32
|
jpayne@69
|
658 * values in the .xz headers will still be verified normally.
|
jpayne@69
|
659 *
|
jpayne@69
|
660 * Don't use this flag unless you know what you are doing. Possible reasons
|
jpayne@69
|
661 * to use this flag:
|
jpayne@69
|
662 *
|
jpayne@69
|
663 * - Trying to recover data from a corrupt .xz file.
|
jpayne@69
|
664 *
|
jpayne@69
|
665 * - Speeding up decompression, which matters mostly with SHA-256
|
jpayne@69
|
666 * or with files that have compressed extremely well. It's recommended
|
jpayne@69
|
667 * to not use this flag for this purpose unless the file integrity is
|
jpayne@69
|
668 * verified externally in some other way.
|
jpayne@69
|
669 *
|
jpayne@69
|
670 * Support for this flag was added in liblzma 5.1.4beta.
|
jpayne@69
|
671 */
|
jpayne@69
|
672 #define LZMA_IGNORE_CHECK UINT32_C(0x10)
|
jpayne@69
|
673
|
jpayne@69
|
674
|
jpayne@69
|
675 /**
|
jpayne@69
|
676 * This flag enables decoding of concatenated files with file formats that
|
jpayne@69
|
677 * allow concatenating compressed files as is. From the formats currently
|
jpayne@69
|
678 * supported by liblzma, only the .xz and .lz formats allow concatenated
|
jpayne@69
|
679 * files. Concatenated files are not allowed with the legacy .lzma format.
|
jpayne@69
|
680 *
|
jpayne@69
|
681 * This flag also affects the usage of the 'action' argument for lzma_code().
|
jpayne@69
|
682 * When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END
|
jpayne@69
|
683 * unless LZMA_FINISH is used as 'action'. Thus, the application has to set
|
jpayne@69
|
684 * LZMA_FINISH in the same way as it does when encoding.
|
jpayne@69
|
685 *
|
jpayne@69
|
686 * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH
|
jpayne@69
|
687 * as 'action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
|
jpayne@69
|
688 */
|
jpayne@69
|
689 #define LZMA_CONCATENATED UINT32_C(0x08)
|
jpayne@69
|
690
|
jpayne@69
|
691
|
jpayne@69
|
692 /**
|
jpayne@69
|
693 * This flag makes the threaded decoder report errors (like LZMA_DATA_ERROR)
|
jpayne@69
|
694 * as soon as they are detected. This saves time when the application has no
|
jpayne@69
|
695 * interest in a partially decompressed truncated or corrupt file. Note that
|
jpayne@69
|
696 * due to timing randomness, if the same truncated or corrupt input is
|
jpayne@69
|
697 * decompressed multiple times with this flag, a different amount of output
|
jpayne@69
|
698 * may be produced by different runs, and even the error code might vary.
|
jpayne@69
|
699 *
|
jpayne@69
|
700 * When using LZMA_FAIL_FAST, it is recommended to use LZMA_FINISH to tell
|
jpayne@69
|
701 * the decoder when no more input will be coming because it can help fast
|
jpayne@69
|
702 * detection and reporting of truncated files. Note that in this situation
|
jpayne@69
|
703 * truncated files might be diagnosed with LZMA_DATA_ERROR instead of
|
jpayne@69
|
704 * LZMA_OK or LZMA_BUF_ERROR!
|
jpayne@69
|
705 *
|
jpayne@69
|
706 * Without this flag the threaded decoder will provide as much output as
|
jpayne@69
|
707 * possible at first and then report the pending error. This default behavior
|
jpayne@69
|
708 * matches the single-threaded decoder and provides repeatable behavior
|
jpayne@69
|
709 * with truncated or corrupt input. There are a few special cases where the
|
jpayne@69
|
710 * behavior can still differ like memory allocation failures (LZMA_MEM_ERROR).
|
jpayne@69
|
711 *
|
jpayne@69
|
712 * Single-threaded decoders currently ignore this flag.
|
jpayne@69
|
713 *
|
jpayne@69
|
714 * Support for this flag was added in liblzma 5.3.3alpha. Note that in older
|
jpayne@69
|
715 * versions this flag isn't supported (LZMA_OPTIONS_ERROR) even by functions
|
jpayne@69
|
716 * that ignore this flag in newer liblzma versions.
|
jpayne@69
|
717 */
|
jpayne@69
|
718 #define LZMA_FAIL_FAST UINT32_C(0x20)
|
jpayne@69
|
719
|
jpayne@69
|
720
|
jpayne@69
|
721 /**
|
jpayne@69
|
722 * \brief Initialize .xz Stream decoder
|
jpayne@69
|
723 *
|
jpayne@69
|
724 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
725 * with LZMA_STREAM_INIT.
|
jpayne@69
|
726 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
jpayne@69
|
727 * to effectively disable the limiter. liblzma
|
jpayne@69
|
728 * 5.2.3 and earlier don't allow 0 here and return
|
jpayne@69
|
729 * LZMA_PROG_ERROR; later versions treat 0 as if 1
|
jpayne@69
|
730 * had been specified.
|
jpayne@69
|
731 * \param flags Bitwise-or of zero or more of the decoder flags:
|
jpayne@69
|
732 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
|
jpayne@69
|
733 * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,
|
jpayne@69
|
734 * LZMA_CONCATENATED, LZMA_FAIL_FAST
|
jpayne@69
|
735 *
|
jpayne@69
|
736 * \return Possible lzma_ret values:
|
jpayne@69
|
737 * - LZMA_OK: Initialization was successful.
|
jpayne@69
|
738 * - LZMA_MEM_ERROR: Cannot allocate memory.
|
jpayne@69
|
739 * - LZMA_OPTIONS_ERROR: Unsupported flags
|
jpayne@69
|
740 * - LZMA_PROG_ERROR
|
jpayne@69
|
741 */
|
jpayne@69
|
742 extern LZMA_API(lzma_ret) lzma_stream_decoder(
|
jpayne@69
|
743 lzma_stream *strm, uint64_t memlimit, uint32_t flags)
|
jpayne@69
|
744 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
745
|
jpayne@69
|
746
|
jpayne@69
|
747 /**
|
jpayne@69
|
748 * \brief Initialize multithreaded .xz Stream decoder
|
jpayne@69
|
749 *
|
jpayne@69
|
750 * The decoder can decode multiple Blocks in parallel. This requires that each
|
jpayne@69
|
751 * Block Header contains the Compressed Size and Uncompressed size fields
|
jpayne@69
|
752 * which are added by the multi-threaded encoder, see lzma_stream_encoder_mt().
|
jpayne@69
|
753 *
|
jpayne@69
|
754 * A Stream with one Block will only utilize one thread. A Stream with multiple
|
jpayne@69
|
755 * Blocks but without size information in Block Headers will be processed in
|
jpayne@69
|
756 * single-threaded mode in the same way as done by lzma_stream_decoder().
|
jpayne@69
|
757 * Concatenated Streams are processed one Stream at a time; no inter-Stream
|
jpayne@69
|
758 * parallelization is done.
|
jpayne@69
|
759 *
|
jpayne@69
|
760 * This function behaves like lzma_stream_decoder() when options->threads == 1
|
jpayne@69
|
761 * and options->memlimit_threading <= 1.
|
jpayne@69
|
762 *
|
jpayne@69
|
763 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
764 * with LZMA_STREAM_INIT.
|
jpayne@69
|
765 * \param options Pointer to multithreaded compression options
|
jpayne@69
|
766 *
|
jpayne@69
|
767 * \return Possible lzma_ret values:
|
jpayne@69
|
768 * - LZMA_OK: Initialization was successful.
|
jpayne@69
|
769 * - LZMA_MEM_ERROR: Cannot allocate memory.
|
jpayne@69
|
770 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
|
jpayne@69
|
771 * - LZMA_OPTIONS_ERROR: Unsupported flags.
|
jpayne@69
|
772 * - LZMA_PROG_ERROR
|
jpayne@69
|
773 */
|
jpayne@69
|
774 extern LZMA_API(lzma_ret) lzma_stream_decoder_mt(
|
jpayne@69
|
775 lzma_stream *strm, const lzma_mt *options)
|
jpayne@69
|
776 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
777
|
jpayne@69
|
778
|
jpayne@69
|
779 /**
|
jpayne@69
|
780 * \brief Decode .xz, .lzma, and .lz (lzip) files with autodetection
|
jpayne@69
|
781 *
|
jpayne@69
|
782 * This decoder autodetects between the .xz, .lzma, and .lz file formats,
|
jpayne@69
|
783 * and calls lzma_stream_decoder(), lzma_alone_decoder(), or
|
jpayne@69
|
784 * lzma_lzip_decoder() once the type of the input file has been detected.
|
jpayne@69
|
785 *
|
jpayne@69
|
786 * Support for .lz was added in 5.4.0.
|
jpayne@69
|
787 *
|
jpayne@69
|
788 * If the flag LZMA_CONCATENATED is used and the input is a .lzma file:
|
jpayne@69
|
789 * For historical reasons concatenated .lzma files aren't supported.
|
jpayne@69
|
790 * If there is trailing data after one .lzma stream, lzma_code() will
|
jpayne@69
|
791 * return LZMA_DATA_ERROR. (lzma_alone_decoder() doesn't have such a check
|
jpayne@69
|
792 * as it doesn't support any decoder flags. It will return LZMA_STREAM_END
|
jpayne@69
|
793 * after one .lzma stream.)
|
jpayne@69
|
794 *
|
jpayne@69
|
795 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
796 * with LZMA_STREAM_INIT.
|
jpayne@69
|
797 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
jpayne@69
|
798 * to effectively disable the limiter. liblzma
|
jpayne@69
|
799 * 5.2.3 and earlier don't allow 0 here and return
|
jpayne@69
|
800 * LZMA_PROG_ERROR; later versions treat 0 as if 1
|
jpayne@69
|
801 * had been specified.
|
jpayne@69
|
802 * \param flags Bitwise-or of zero or more of the decoder flags:
|
jpayne@69
|
803 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
|
jpayne@69
|
804 * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,
|
jpayne@69
|
805 * LZMA_CONCATENATED, LZMA_FAIL_FAST
|
jpayne@69
|
806 *
|
jpayne@69
|
807 * \return Possible lzma_ret values:
|
jpayne@69
|
808 * - LZMA_OK: Initialization was successful.
|
jpayne@69
|
809 * - LZMA_MEM_ERROR: Cannot allocate memory.
|
jpayne@69
|
810 * - LZMA_OPTIONS_ERROR: Unsupported flags
|
jpayne@69
|
811 * - LZMA_PROG_ERROR
|
jpayne@69
|
812 */
|
jpayne@69
|
813 extern LZMA_API(lzma_ret) lzma_auto_decoder(
|
jpayne@69
|
814 lzma_stream *strm, uint64_t memlimit, uint32_t flags)
|
jpayne@69
|
815 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
816
|
jpayne@69
|
817
|
jpayne@69
|
818 /**
|
jpayne@69
|
819 * \brief Initialize .lzma decoder (legacy file format)
|
jpayne@69
|
820 *
|
jpayne@69
|
821 * Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
jpayne@69
|
822 * There is no need to use LZMA_FINISH, but it's allowed because it may
|
jpayne@69
|
823 * simplify certain types of applications.
|
jpayne@69
|
824 *
|
jpayne@69
|
825 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
826 * with LZMA_STREAM_INIT.
|
jpayne@69
|
827 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
jpayne@69
|
828 * to effectively disable the limiter. liblzma
|
jpayne@69
|
829 * 5.2.3 and earlier don't allow 0 here and return
|
jpayne@69
|
830 * LZMA_PROG_ERROR; later versions treat 0 as if 1
|
jpayne@69
|
831 * had been specified.
|
jpayne@69
|
832 *
|
jpayne@69
|
833 * \return Possible lzma_ret values:
|
jpayne@69
|
834 * - LZMA_OK
|
jpayne@69
|
835 * - LZMA_MEM_ERROR
|
jpayne@69
|
836 * - LZMA_PROG_ERROR
|
jpayne@69
|
837 */
|
jpayne@69
|
838 extern LZMA_API(lzma_ret) lzma_alone_decoder(
|
jpayne@69
|
839 lzma_stream *strm, uint64_t memlimit)
|
jpayne@69
|
840 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
841
|
jpayne@69
|
842
|
jpayne@69
|
843 /**
|
jpayne@69
|
844 * \brief Initialize .lz (lzip) decoder (a foreign file format)
|
jpayne@69
|
845 *
|
jpayne@69
|
846 * This decoder supports the .lz format version 0 and the unextended .lz
|
jpayne@69
|
847 * format version 1:
|
jpayne@69
|
848 *
|
jpayne@69
|
849 * - Files in the format version 0 were produced by lzip 1.3 and older.
|
jpayne@69
|
850 * Such files aren't common but may be found from file archives
|
jpayne@69
|
851 * as a few source packages were released in this format. People
|
jpayne@69
|
852 * might have old personal files in this format too. Decompression
|
jpayne@69
|
853 * support for the format version 0 was removed in lzip 1.18.
|
jpayne@69
|
854 *
|
jpayne@69
|
855 * - lzip 1.3 added decompression support for .lz format version 1 files.
|
jpayne@69
|
856 * Compression support was added in lzip 1.4. In lzip 1.6 the .lz format
|
jpayne@69
|
857 * version 1 was extended to support the Sync Flush marker. This extension
|
jpayne@69
|
858 * is not supported by liblzma. lzma_code() will return LZMA_DATA_ERROR
|
jpayne@69
|
859 * at the location of the Sync Flush marker. In practice files with
|
jpayne@69
|
860 * the Sync Flush marker are very rare and thus liblzma can decompress
|
jpayne@69
|
861 * almost all .lz files.
|
jpayne@69
|
862 *
|
jpayne@69
|
863 * Just like with lzma_stream_decoder() for .xz files, LZMA_CONCATENATED
|
jpayne@69
|
864 * should be used when decompressing normal standalone .lz files.
|
jpayne@69
|
865 *
|
jpayne@69
|
866 * The .lz format allows putting non-.lz data at the end of a file after at
|
jpayne@69
|
867 * least one valid .lz member. That is, one can append custom data at the end
|
jpayne@69
|
868 * of a .lz file and the decoder is required to ignore it. In liblzma this
|
jpayne@69
|
869 * is relevant only when LZMA_CONCATENATED is used. In that case lzma_code()
|
jpayne@69
|
870 * will return LZMA_STREAM_END and leave lzma_stream.next_in pointing to
|
jpayne@69
|
871 * the first byte of the non-.lz data. An exception to this is if the first
|
jpayne@69
|
872 * 1-3 bytes of the non-.lz data are identical to the .lz magic bytes
|
jpayne@69
|
873 * (0x4C, 0x5A, 0x49, 0x50; "LZIP" in US-ASCII). In such a case the 1-3 bytes
|
jpayne@69
|
874 * will have been ignored by lzma_code(). If one wishes to locate the non-.lz
|
jpayne@69
|
875 * data reliably, one must ensure that the first byte isn't 0x4C. Actually
|
jpayne@69
|
876 * one should ensure that none of the first four bytes of trailing data are
|
jpayne@69
|
877 * equal to the magic bytes because lzip >= 1.20 requires it by default.
|
jpayne@69
|
878 *
|
jpayne@69
|
879 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
880 * with LZMA_STREAM_INIT.
|
jpayne@69
|
881 * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
jpayne@69
|
882 * to effectively disable the limiter.
|
jpayne@69
|
883 * \param flags Bitwise-or of flags, or zero for no flags.
|
jpayne@69
|
884 * All decoder flags listed above are supported
|
jpayne@69
|
885 * although only LZMA_CONCATENATED and (in very rare
|
jpayne@69
|
886 * cases) LZMA_IGNORE_CHECK are actually useful.
|
jpayne@69
|
887 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
|
jpayne@69
|
888 * and LZMA_FAIL_FAST do nothing. LZMA_TELL_ANY_CHECK
|
jpayne@69
|
889 * is supported for consistency only as CRC32 is
|
jpayne@69
|
890 * always used in the .lz format.
|
jpayne@69
|
891 *
|
jpayne@69
|
892 * \return Possible lzma_ret values:
|
jpayne@69
|
893 * - LZMA_OK: Initialization was successful.
|
jpayne@69
|
894 * - LZMA_MEM_ERROR: Cannot allocate memory.
|
jpayne@69
|
895 * - LZMA_OPTIONS_ERROR: Unsupported flags
|
jpayne@69
|
896 * - LZMA_PROG_ERROR
|
jpayne@69
|
897 */
|
jpayne@69
|
898 extern LZMA_API(lzma_ret) lzma_lzip_decoder(
|
jpayne@69
|
899 lzma_stream *strm, uint64_t memlimit, uint32_t flags)
|
jpayne@69
|
900 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
901
|
jpayne@69
|
902
|
jpayne@69
|
903 /**
|
jpayne@69
|
904 * \brief Single-call .xz Stream decoder
|
jpayne@69
|
905 *
|
jpayne@69
|
906 * \param memlimit Pointer to how much memory the decoder is allowed
|
jpayne@69
|
907 * to allocate. The value pointed by this pointer is
|
jpayne@69
|
908 * modified if and only if LZMA_MEMLIMIT_ERROR is
|
jpayne@69
|
909 * returned.
|
jpayne@69
|
910 * \param flags Bitwise-or of zero or more of the decoder flags:
|
jpayne@69
|
911 * LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
|
jpayne@69
|
912 * LZMA_IGNORE_CHECK, LZMA_CONCATENATED,
|
jpayne@69
|
913 * LZMA_FAIL_FAST. Note that LZMA_TELL_ANY_CHECK
|
jpayne@69
|
914 * is not allowed and will return LZMA_PROG_ERROR.
|
jpayne@69
|
915 * \param allocator lzma_allocator for custom allocator functions.
|
jpayne@69
|
916 * Set to NULL to use malloc() and free().
|
jpayne@69
|
917 * \param in Beginning of the input buffer
|
jpayne@69
|
918 * \param in_pos The next byte will be read from in[*in_pos].
|
jpayne@69
|
919 * *in_pos is updated only if decoding succeeds.
|
jpayne@69
|
920 * \param in_size Size of the input buffer; the first byte that
|
jpayne@69
|
921 * won't be read is in[in_size].
|
jpayne@69
|
922 * \param[out] out Beginning of the output buffer
|
jpayne@69
|
923 * \param[out] out_pos The next byte will be written to out[*out_pos].
|
jpayne@69
|
924 * *out_pos is updated only if decoding succeeds.
|
jpayne@69
|
925 * \param out_size Size of the out buffer; the first byte into
|
jpayne@69
|
926 * which no data is written to is out[out_size].
|
jpayne@69
|
927 *
|
jpayne@69
|
928 * \return Possible lzma_ret values:
|
jpayne@69
|
929 * - LZMA_OK: Decoding was successful.
|
jpayne@69
|
930 * - LZMA_FORMAT_ERROR
|
jpayne@69
|
931 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
932 * - LZMA_DATA_ERROR
|
jpayne@69
|
933 * - LZMA_NO_CHECK: This can be returned only if using
|
jpayne@69
|
934 * the LZMA_TELL_NO_CHECK flag.
|
jpayne@69
|
935 * - LZMA_UNSUPPORTED_CHECK: This can be returned only if using
|
jpayne@69
|
936 * the LZMA_TELL_UNSUPPORTED_CHECK flag.
|
jpayne@69
|
937 * - LZMA_MEM_ERROR
|
jpayne@69
|
938 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
|
jpayne@69
|
939 * The minimum required memlimit value was stored to *memlimit.
|
jpayne@69
|
940 * - LZMA_BUF_ERROR: Output buffer was too small.
|
jpayne@69
|
941 * - LZMA_PROG_ERROR
|
jpayne@69
|
942 */
|
jpayne@69
|
943 extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
|
jpayne@69
|
944 uint64_t *memlimit, uint32_t flags,
|
jpayne@69
|
945 const lzma_allocator *allocator,
|
jpayne@69
|
946 const uint8_t *in, size_t *in_pos, size_t in_size,
|
jpayne@69
|
947 uint8_t *out, size_t *out_pos, size_t out_size)
|
jpayne@69
|
948 lzma_nothrow lzma_attr_warn_unused_result;
|
jpayne@69
|
949
|
jpayne@69
|
950
|
jpayne@69
|
951 /**
|
jpayne@69
|
952 * \brief MicroLZMA decoder
|
jpayne@69
|
953 *
|
jpayne@69
|
954 * See lzma_microlzma_encoder() for more information.
|
jpayne@69
|
955 *
|
jpayne@69
|
956 * The lzma_code() usage with this decoder is completely normal. The
|
jpayne@69
|
957 * special behavior of lzma_code() applies to lzma_microlzma_encoder() only.
|
jpayne@69
|
958 *
|
jpayne@69
|
959 * \param strm Pointer to lzma_stream that is at least initialized
|
jpayne@69
|
960 * with LZMA_STREAM_INIT.
|
jpayne@69
|
961 * \param comp_size Compressed size of the MicroLZMA stream.
|
jpayne@69
|
962 * The caller must somehow know this exactly.
|
jpayne@69
|
963 * \param uncomp_size Uncompressed size of the MicroLZMA stream.
|
jpayne@69
|
964 * If the exact uncompressed size isn't known, this
|
jpayne@69
|
965 * can be set to a value that is at most as big as
|
jpayne@69
|
966 * the exact uncompressed size would be, but then the
|
jpayne@69
|
967 * next argument uncomp_size_is_exact must be false.
|
jpayne@69
|
968 * \param uncomp_size_is_exact
|
jpayne@69
|
969 * If true, uncomp_size must be exactly correct.
|
jpayne@69
|
970 * This will improve error detection at the end of
|
jpayne@69
|
971 * the stream. If the exact uncompressed size isn't
|
jpayne@69
|
972 * known, this must be false. uncomp_size must still
|
jpayne@69
|
973 * be at most as big as the exact uncompressed size
|
jpayne@69
|
974 * is. Setting this to false when the exact size is
|
jpayne@69
|
975 * known will work but error detection at the end of
|
jpayne@69
|
976 * the stream will be weaker.
|
jpayne@69
|
977 * \param dict_size LZMA dictionary size that was used when
|
jpayne@69
|
978 * compressing the data. It is OK to use a bigger
|
jpayne@69
|
979 * value too but liblzma will then allocate more
|
jpayne@69
|
980 * memory than would actually be required and error
|
jpayne@69
|
981 * detection will be slightly worse. (Note that with
|
jpayne@69
|
982 * the implementation in XZ Embedded it doesn't
|
jpayne@69
|
983 * affect the memory usage if one specifies bigger
|
jpayne@69
|
984 * dictionary than actually required.)
|
jpayne@69
|
985 *
|
jpayne@69
|
986 * \return Possible lzma_ret values:
|
jpayne@69
|
987 * - LZMA_OK
|
jpayne@69
|
988 * - LZMA_MEM_ERROR
|
jpayne@69
|
989 * - LZMA_OPTIONS_ERROR
|
jpayne@69
|
990 * - LZMA_PROG_ERROR
|
jpayne@69
|
991 */
|
jpayne@69
|
992 extern LZMA_API(lzma_ret) lzma_microlzma_decoder(
|
jpayne@69
|
993 lzma_stream *strm, uint64_t comp_size,
|
jpayne@69
|
994 uint64_t uncomp_size, lzma_bool uncomp_size_is_exact,
|
jpayne@69
|
995 uint32_t dict_size) lzma_nothrow;
|