3 * \brief .lzma Block handling
5 * \author Copyright (C) 1999-2006 Igor Pavlov
6 * \author Copyright (C) 2007 Lasse Collin
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
19 #ifndef LZMA_H_INTERNAL
20 # error Never include this file directly. Use <lzma.h> instead.
25 * \brief Options for the Block Header encoder and decoder
27 * Different things use different parts of this structure. Some read
28 * some members, other functions write, and some do both. Only the
29 * members listed for reading need to be initialized when the specified
30 * functions are called. The members marked for writing will be assigned
31 * new values at some point either by calling the given function or by
32 * later calls to lzma_code().
36 * \brief Type of integrity Check
38 * The type of the integrity Check is not stored into the Block
39 * Header, thus its value must be provided also when decoding.
42 * - lzma_block_encoder()
43 * - lzma_block_decoder()
45 lzma_check_type check;
48 * \brief Precense of CRC32 of the Block Header
50 * Set this to true if CRC32 of the Block Header should be
51 * calculated and stored in the Block Header.
53 * There is no way to autodetect if CRC32 is present in the Block
54 * Header, thus this information must be provided also when decoding.
57 * - lzma_block_header_size()
58 * - lzma_block_header_encoder()
59 * - lzma_block_header_decoder()
64 * \brief Usage of End of Payload Marker
66 * If this is true, End of Payload Marker is used even if
67 * Uncompressed Size is known.
70 * - lzma_block_header_encoder()
71 * - lzma_block_encoder()
72 * - lzma_block_decoder()
75 * - lzma_block_header_decoder()
80 * \brief True if the Block is a Metadata Block
82 * If this is true, the Metadata bit will be set in the Block Header.
83 * It is up to the application to store correctly formatted data
84 * into Metadata Block.
87 * - lzma_block_header_encoder()
90 * - lzma_block_header_decoder()
92 lzma_bool is_metadata;
95 * \brief True if Uncompressed Size is in Block Footer
98 * - lzma_block_encoder()
99 * - lzma_block_decoder()
101 lzma_bool has_uncompressed_size_in_footer;
104 * \brief True if Backward Size is in Block Footer
107 * - lzma_block_encoder()
108 * - lzma_block_decoder()
110 lzma_bool has_backward_size;
113 * \brief True if Block coder should take care of Padding
115 * In liblzma, Stream decoder sets this to true when decoding
116 * Header Metadata Block or Data Blocks from Multi-Block Stream,
117 * and to false when decoding Single-Block Stream or Footer
118 * Metadata Block from a Multi-Block Stream.
121 * - lzma_block_encoder()
122 * - lzma_block_decoder()
124 lzma_bool handle_padding;
127 * \brief Size of the Compressed Data in bytes
129 * Usually you don't know this value when encoding in streamed mode.
130 * In non-streamed mode you can reserve space for this field when
131 * encoding the Block Header the first time, and then re-encode the
132 * Block Header and copy it over the original one after the encoding
133 * of the Block has been finished.
136 * - lzma_block_header_size()
137 * - lzma_block_header_encoder()
138 * - lzma_block_encoder()
139 * - lzma_block_decoder()
142 * - lzma_block_header_decoder()
143 * - lzma_block_encoder()
144 * - lzma_block_decoder()
146 lzma_vli compressed_size;
149 * \brief Uncompressed Size in bytes
151 * Encoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is stored
152 * to the Uncompressed Size field in the Block Header. The real
153 * uncompressed size of the data being compressed must match
154 * the Uncompressed Size or LZMA_HEADER_ERROR is returned.
156 * If Uncompressed Size is unknown, End of Payload Marker must
157 * be used. If uncompressed_size == LZMA_VLI_VALUE_UNKNOWN and
158 * has_eopm == 0, LZMA_HEADER_ERROR will be returned.
160 * Decoder: If this value is not LZMA_VLI_VALUE_UNKNOWN, it is
161 * compared to the real Uncompressed Size. If they do not match,
162 * LZMA_HEADER_ERROR is returned.
165 * - lzma_block_header_size()
166 * - lzma_block_header_encoder()
167 * - lzma_block_encoder()
168 * - lzma_block_decoder()
171 * - lzma_block_header_decoder()
172 * - lzma_block_encoder()
173 * - lzma_block_decoder()
175 lzma_vli uncompressed_size;
178 * \brief Number of bytes to reserve for Compressed Size
180 * This is useful if you want to be able to store the Compressed Size
181 * to the Block Header, but you don't know it when starting to encode.
182 * Setting this to non-zero value at maximum of LZMA_VLI_BYTES_MAX,
183 * the Block Header encoder will force the Compressed Size field to
184 * occupy specified number of bytes. You can later rewrite the Block
185 * Header to contain correct information by using otherwise identical
186 * lzma_options_block structure except the correct compressed_size.
189 * - lzma_block_header_size()
190 * - lzma_block_header_encoder()
193 * - lzma_block_header_decoder()
195 uint32_t compressed_reserve;
198 * \brief Number of bytes to reserve for Uncompressed Size
200 * See the description of compressed_size above.
203 * - lzma_block_header_size()
204 * - lzma_block_header_encoder()
207 * - lzma_block_header_decoder()
209 uint32_t uncompressed_reserve;
212 * \brief Total Size of the Block in bytes
214 * This is useful in the decoder, which can verify the Total Size
215 * if it is known from Index.
218 * - lzma_block_encoder()
219 * - lzma_block_decoder()
222 * - lzma_block_encoder()
223 * - lzma_block_decoder()
228 * \brief Upper limit of Total Size
231 * - lzma_block_encoder()
232 * - lzma_block_decoder()
234 lzma_vli total_limit;
237 * \brief Upper limit of Uncompressed Size
240 * - lzma_block_encoder()
241 * - lzma_block_decoder()
243 lzma_vli uncompressed_limit;
246 * \brief Array of filters
248 * There can be at maximum of seven filters. The end of the array
249 * is marked with .id = LZMA_VLI_VALUE_UNKNOWN. Minimum number of
250 * filters is zero; in that case, an implicit Copy filter is used.
253 * - lzma_block_header_size()
254 * - lzma_block_header_encoder()
255 * - lzma_block_encoder()
256 * - lzma_block_decoder()
259 * - lzma_block_header_decoder(): Note that this does NOT free()
260 * the old filter options structures. If decoding fails, the
261 * caller must take care of freeing the options structures
262 * that may have been allocated and decoded before the error
265 lzma_options_filter filters[8];
268 * \brief Size of the Padding field
270 * The Padding field exist to allow aligning the Compressed Data field
271 * optimally in the Block. See lzma_options_stream.alignment in
272 * stream.h for more information.
274 * If you want the Block Header encoder to automatically calculate
275 * optimal size for the Padding field by looking at the information
276 * in filters[], set this to LZMA_BLOCK_HEADER_PADDING_AUTO. In that
277 * case, you must also set the aligmnet variable to tell the the
278 * encoder the aligmnet of the beginning of the Block Header.
280 * The decoder never sets this to LZMA_BLOCK_HEADER_PADDING_AUTO.
283 * - lzma_block_header_size()
284 * - lzma_block_header_encoder(): Note that this doesn't
285 * accept LZMA_BLOCK_HEADER_PADDING_AUTO.
287 * Written by (these never set padding to
288 * LZMA_BLOCK_HEADER_PADDING_AUTO):
289 * - lzma_block_header_size()
290 * - lzma_block_header_decoder()
293 # define LZMA_BLOCK_HEADER_PADDING_AUTO (-1)
294 # define LZMA_BLOCK_HEADER_PADDING_MIN 0
295 # define LZMA_BLOCK_HEADER_PADDING_MAX 31
298 * \brief Alignment of the beginning of the Block Header
300 * This variable is read only if padding has been set to
301 * LZMA_BLOCK_HEADER_PADDING_AUTO.
304 * - lzma_block_header_size()
305 * - lzma_block_header_encoder()
310 * \brief Size of the Block Header
313 * - lzma_block_encoder()
314 * - lzma_block_decoder()
317 * - lzma_block_header_size()
318 * - lzma_block_header_decoder()
320 uint32_t header_size;
322 } lzma_options_block;
326 * \brief Calculates the size of Header Padding and Block Header
328 * \return - LZMA_OK: Size calculated successfully and stored to
329 * options->header_size.
330 * - LZMA_HEADER_ERROR: Unsupported filters or filter options.
331 * - LZMA_PROG_ERROR: Invalid options
333 * \note This doesn't check that all the options are valid i.e. this
334 * may return LZMA_OK even if lzma_block_header_encode() or
335 * lzma_block_encoder() would fail.
337 extern lzma_ret lzma_block_header_size(lzma_options_block *options);
341 * \brief Encodes Block Header
343 * Encoding of the Block options is done with a single call instead of
344 * first initializing and then doing the actual work with lzma_code().
346 * \param out Beginning of the output buffer. This must be
347 * at least options->header_size bytes.
348 * \param options Block options to be encoded.
350 * \return - LZMA_OK: Encoding was successful. options->header_size
351 * bytes were written to output buffer.
352 * - LZMA_HEADER_ERROR: Invalid or unsupported options.
355 extern lzma_ret lzma_block_header_encode(
356 uint8_t *out, const lzma_options_block *options);
360 * \brief Initializes Block Header decoder
362 * Because the results of this decoder are placed into *options,
363 * strm->next_in, strm->avail_in, and strm->total_in are not used.
365 * The only valid `action' with lzma_code() is LZMA_RUN.
367 * \return - LZMA_OK: Encoding was successful. options->header_size
368 * bytes were written to output buffer.
369 * - LZMA_HEADER_ERROR: Invalid or unsupported options.
372 extern lzma_ret lzma_block_header_decoder(
373 lzma_stream *strm, lzma_options_block *options);
377 * \brief Initializes .lzma Block encoder
379 * This function is required for multi-thread encoding. It may also be
380 * useful when implementing custom file formats.
382 * \return - LZMA_OK: All good, continue with lzma_code().
384 * - LZMA_HEADER_ERROR
385 * - LZMA_DATA_ERROR: Limits (total_limit and uncompressed_limit)
386 * have been reached already.
387 * - LZMA_UNSUPPORTED_CHECK: options->check specfies a Check
388 * that is not supported by this buid of liblzma. Initializing
389 * the encoder failed.
392 * lzma_code() can return FIXME
394 extern lzma_ret lzma_block_encoder(
395 lzma_stream *strm, lzma_options_block *options);
399 * \brief Initializes decoder for .lzma Block
401 * \return - LZMA_OK: All good, continue with lzma_code().
402 * - LZMA_UNSUPPORTED_CHECK: Initialization was successful, but
403 * the given Check type is not supported, thus Check will be
408 extern lzma_ret lzma_block_decoder(
409 lzma_stream *strm, lzma_options_block *options);