annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/lzma/block.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /* SPDX-License-Identifier: 0BSD */
jpayne@69 2
jpayne@69 3 /**
jpayne@69 4 * \file lzma/block.h
jpayne@69 5 * \brief .xz Block handling
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 * \brief Options for the Block and Block Header encoders and decoders
jpayne@69 20 *
jpayne@69 21 * Different Block handling functions use different parts of this structure.
jpayne@69 22 * Some read some members, other functions write, and some do both. Only the
jpayne@69 23 * members listed for reading need to be initialized when the specified
jpayne@69 24 * functions are called. The members marked for writing will be assigned
jpayne@69 25 * new values at some point either by calling the given function or by
jpayne@69 26 * later calls to lzma_code().
jpayne@69 27 */
jpayne@69 28 typedef struct {
jpayne@69 29 /**
jpayne@69 30 * \brief Block format version
jpayne@69 31 *
jpayne@69 32 * To prevent API and ABI breakages when new features are needed,
jpayne@69 33 * a version number is used to indicate which members in this
jpayne@69 34 * structure are in use:
jpayne@69 35 * - liblzma >= 5.0.0: version = 0 is supported.
jpayne@69 36 * - liblzma >= 5.1.4beta: Support for version = 1 was added,
jpayne@69 37 * which adds the ignore_check member.
jpayne@69 38 *
jpayne@69 39 * If version is greater than one, most Block related functions
jpayne@69 40 * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works
jpayne@69 41 * with any version value).
jpayne@69 42 *
jpayne@69 43 * Read by:
jpayne@69 44 * - lzma_block_header_size()
jpayne@69 45 * - lzma_block_header_encode()
jpayne@69 46 * - lzma_block_header_decode()
jpayne@69 47 * - lzma_block_compressed_size()
jpayne@69 48 * - lzma_block_unpadded_size()
jpayne@69 49 * - lzma_block_total_size()
jpayne@69 50 * - lzma_block_encoder()
jpayne@69 51 * - lzma_block_decoder()
jpayne@69 52 * - lzma_block_buffer_encode()
jpayne@69 53 * - lzma_block_uncomp_encode()
jpayne@69 54 * - lzma_block_buffer_decode()
jpayne@69 55 *
jpayne@69 56 * Written by:
jpayne@69 57 * - lzma_block_header_decode()
jpayne@69 58 */
jpayne@69 59 uint32_t version;
jpayne@69 60
jpayne@69 61 /**
jpayne@69 62 * \brief Size of the Block Header field in bytes
jpayne@69 63 *
jpayne@69 64 * This is always a multiple of four.
jpayne@69 65 *
jpayne@69 66 * Read by:
jpayne@69 67 * - lzma_block_header_encode()
jpayne@69 68 * - lzma_block_header_decode()
jpayne@69 69 * - lzma_block_compressed_size()
jpayne@69 70 * - lzma_block_unpadded_size()
jpayne@69 71 * - lzma_block_total_size()
jpayne@69 72 * - lzma_block_decoder()
jpayne@69 73 * - lzma_block_buffer_decode()
jpayne@69 74 *
jpayne@69 75 * Written by:
jpayne@69 76 * - lzma_block_header_size()
jpayne@69 77 * - lzma_block_buffer_encode()
jpayne@69 78 * - lzma_block_uncomp_encode()
jpayne@69 79 */
jpayne@69 80 uint32_t header_size;
jpayne@69 81 # define LZMA_BLOCK_HEADER_SIZE_MIN 8
jpayne@69 82 # define LZMA_BLOCK_HEADER_SIZE_MAX 1024
jpayne@69 83
jpayne@69 84 /**
jpayne@69 85 * \brief Type of integrity Check
jpayne@69 86 *
jpayne@69 87 * The Check ID is not stored into the Block Header, thus its value
jpayne@69 88 * must be provided also when decoding.
jpayne@69 89 *
jpayne@69 90 * Read by:
jpayne@69 91 * - lzma_block_header_encode()
jpayne@69 92 * - lzma_block_header_decode()
jpayne@69 93 * - lzma_block_compressed_size()
jpayne@69 94 * - lzma_block_unpadded_size()
jpayne@69 95 * - lzma_block_total_size()
jpayne@69 96 * - lzma_block_encoder()
jpayne@69 97 * - lzma_block_decoder()
jpayne@69 98 * - lzma_block_buffer_encode()
jpayne@69 99 * - lzma_block_buffer_decode()
jpayne@69 100 */
jpayne@69 101 lzma_check check;
jpayne@69 102
jpayne@69 103 /**
jpayne@69 104 * \brief Size of the Compressed Data in bytes
jpayne@69 105 *
jpayne@69 106 * Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder
jpayne@69 107 * will store this value to the Block Header. Block encoder doesn't
jpayne@69 108 * care about this value, but will set it once the encoding has been
jpayne@69 109 * finished.
jpayne@69 110 *
jpayne@69 111 * Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will
jpayne@69 112 * verify that the size of the Compressed Data field matches
jpayne@69 113 * compressed_size.
jpayne@69 114 *
jpayne@69 115 * Usually you don't know this value when encoding in streamed mode,
jpayne@69 116 * and thus cannot write this field into the Block Header.
jpayne@69 117 *
jpayne@69 118 * In non-streamed mode you can reserve space for this field before
jpayne@69 119 * encoding the actual Block. After encoding the data, finish the
jpayne@69 120 * Block by encoding the Block Header. Steps in detail:
jpayne@69 121 *
jpayne@69 122 * - Set compressed_size to some big enough value. If you don't know
jpayne@69 123 * better, use LZMA_VLI_MAX, but remember that bigger values take
jpayne@69 124 * more space in Block Header.
jpayne@69 125 *
jpayne@69 126 * - Call lzma_block_header_size() to see how much space you need to
jpayne@69 127 * reserve for the Block Header.
jpayne@69 128 *
jpayne@69 129 * - Encode the Block using lzma_block_encoder() and lzma_code().
jpayne@69 130 * It sets compressed_size to the correct value.
jpayne@69 131 *
jpayne@69 132 * - Use lzma_block_header_encode() to encode the Block Header.
jpayne@69 133 * Because space was reserved in the first step, you don't need
jpayne@69 134 * to call lzma_block_header_size() anymore, because due to
jpayne@69 135 * reserving, header_size has to be big enough. If it is "too big",
jpayne@69 136 * lzma_block_header_encode() will add enough Header Padding to
jpayne@69 137 * make Block Header to match the size specified by header_size.
jpayne@69 138 *
jpayne@69 139 * Read by:
jpayne@69 140 * - lzma_block_header_size()
jpayne@69 141 * - lzma_block_header_encode()
jpayne@69 142 * - lzma_block_compressed_size()
jpayne@69 143 * - lzma_block_unpadded_size()
jpayne@69 144 * - lzma_block_total_size()
jpayne@69 145 * - lzma_block_decoder()
jpayne@69 146 * - lzma_block_buffer_decode()
jpayne@69 147 *
jpayne@69 148 * Written by:
jpayne@69 149 * - lzma_block_header_decode()
jpayne@69 150 * - lzma_block_compressed_size()
jpayne@69 151 * - lzma_block_encoder()
jpayne@69 152 * - lzma_block_decoder()
jpayne@69 153 * - lzma_block_buffer_encode()
jpayne@69 154 * - lzma_block_uncomp_encode()
jpayne@69 155 * - lzma_block_buffer_decode()
jpayne@69 156 */
jpayne@69 157 lzma_vli compressed_size;
jpayne@69 158
jpayne@69 159 /**
jpayne@69 160 * \brief Uncompressed Size in bytes
jpayne@69 161 *
jpayne@69 162 * This is handled very similarly to compressed_size above.
jpayne@69 163 *
jpayne@69 164 * uncompressed_size is needed by fewer functions than
jpayne@69 165 * compressed_size. This is because uncompressed_size isn't
jpayne@69 166 * needed to validate that Block stays within proper limits.
jpayne@69 167 *
jpayne@69 168 * Read by:
jpayne@69 169 * - lzma_block_header_size()
jpayne@69 170 * - lzma_block_header_encode()
jpayne@69 171 * - lzma_block_decoder()
jpayne@69 172 * - lzma_block_buffer_decode()
jpayne@69 173 *
jpayne@69 174 * Written by:
jpayne@69 175 * - lzma_block_header_decode()
jpayne@69 176 * - lzma_block_encoder()
jpayne@69 177 * - lzma_block_decoder()
jpayne@69 178 * - lzma_block_buffer_encode()
jpayne@69 179 * - lzma_block_uncomp_encode()
jpayne@69 180 * - lzma_block_buffer_decode()
jpayne@69 181 */
jpayne@69 182 lzma_vli uncompressed_size;
jpayne@69 183
jpayne@69 184 /**
jpayne@69 185 * \brief Array of filters
jpayne@69 186 *
jpayne@69 187 * There can be 1-4 filters. The end of the array is marked with
jpayne@69 188 * .id = LZMA_VLI_UNKNOWN.
jpayne@69 189 *
jpayne@69 190 * Read by:
jpayne@69 191 * - lzma_block_header_size()
jpayne@69 192 * - lzma_block_header_encode()
jpayne@69 193 * - lzma_block_encoder()
jpayne@69 194 * - lzma_block_decoder()
jpayne@69 195 * - lzma_block_buffer_encode()
jpayne@69 196 * - lzma_block_buffer_decode()
jpayne@69 197 *
jpayne@69 198 * Written by:
jpayne@69 199 * - lzma_block_header_decode(): Note that this does NOT free()
jpayne@69 200 * the old filter options structures. All unused filters[] will
jpayne@69 201 * have .id == LZMA_VLI_UNKNOWN and .options == NULL. If
jpayne@69 202 * decoding fails, all filters[] are guaranteed to be
jpayne@69 203 * LZMA_VLI_UNKNOWN and NULL.
jpayne@69 204 *
jpayne@69 205 * \note Because of the array is terminated with
jpayne@69 206 * .id = LZMA_VLI_UNKNOWN, the actual array must
jpayne@69 207 * have LZMA_FILTERS_MAX + 1 members or the Block
jpayne@69 208 * Header decoder will overflow the buffer.
jpayne@69 209 */
jpayne@69 210 lzma_filter *filters;
jpayne@69 211
jpayne@69 212 /**
jpayne@69 213 * \brief Raw value stored in the Check field
jpayne@69 214 *
jpayne@69 215 * After successful coding, the first lzma_check_size(check) bytes
jpayne@69 216 * of this array contain the raw value stored in the Check field.
jpayne@69 217 *
jpayne@69 218 * Note that CRC32 and CRC64 are stored in little endian byte order.
jpayne@69 219 * Take it into account if you display the Check values to the user.
jpayne@69 220 *
jpayne@69 221 * Written by:
jpayne@69 222 * - lzma_block_encoder()
jpayne@69 223 * - lzma_block_decoder()
jpayne@69 224 * - lzma_block_buffer_encode()
jpayne@69 225 * - lzma_block_uncomp_encode()
jpayne@69 226 * - lzma_block_buffer_decode()
jpayne@69 227 */
jpayne@69 228 uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
jpayne@69 229
jpayne@69 230 /*
jpayne@69 231 * Reserved space to allow possible future extensions without
jpayne@69 232 * breaking the ABI. You should not touch these, because the names
jpayne@69 233 * of these variables may change. These are and will never be used
jpayne@69 234 * with the currently supported options, so it is safe to leave these
jpayne@69 235 * uninitialized.
jpayne@69 236 */
jpayne@69 237
jpayne@69 238 /** \private Reserved member. */
jpayne@69 239 void *reserved_ptr1;
jpayne@69 240
jpayne@69 241 /** \private Reserved member. */
jpayne@69 242 void *reserved_ptr2;
jpayne@69 243
jpayne@69 244 /** \private Reserved member. */
jpayne@69 245 void *reserved_ptr3;
jpayne@69 246
jpayne@69 247 /** \private Reserved member. */
jpayne@69 248 uint32_t reserved_int1;
jpayne@69 249
jpayne@69 250 /** \private Reserved member. */
jpayne@69 251 uint32_t reserved_int2;
jpayne@69 252
jpayne@69 253 /** \private Reserved member. */
jpayne@69 254 lzma_vli reserved_int3;
jpayne@69 255
jpayne@69 256 /** \private Reserved member. */
jpayne@69 257 lzma_vli reserved_int4;
jpayne@69 258
jpayne@69 259 /** \private Reserved member. */
jpayne@69 260 lzma_vli reserved_int5;
jpayne@69 261
jpayne@69 262 /** \private Reserved member. */
jpayne@69 263 lzma_vli reserved_int6;
jpayne@69 264
jpayne@69 265 /** \private Reserved member. */
jpayne@69 266 lzma_vli reserved_int7;
jpayne@69 267
jpayne@69 268 /** \private Reserved member. */
jpayne@69 269 lzma_vli reserved_int8;
jpayne@69 270
jpayne@69 271 /** \private Reserved member. */
jpayne@69 272 lzma_reserved_enum reserved_enum1;
jpayne@69 273
jpayne@69 274 /** \private Reserved member. */
jpayne@69 275 lzma_reserved_enum reserved_enum2;
jpayne@69 276
jpayne@69 277 /** \private Reserved member. */
jpayne@69 278 lzma_reserved_enum reserved_enum3;
jpayne@69 279
jpayne@69 280 /** \private Reserved member. */
jpayne@69 281 lzma_reserved_enum reserved_enum4;
jpayne@69 282
jpayne@69 283 /**
jpayne@69 284 * \brief A flag to Block decoder to not verify the Check field
jpayne@69 285 *
jpayne@69 286 * This member is supported by liblzma >= 5.1.4beta if .version >= 1.
jpayne@69 287 *
jpayne@69 288 * If this is set to true, the integrity check won't be calculated
jpayne@69 289 * and verified. Unless you know what you are doing, you should
jpayne@69 290 * leave this to false. (A reason to set this to true is when the
jpayne@69 291 * file integrity is verified externally anyway and you want to
jpayne@69 292 * speed up the decompression, which matters mostly when using
jpayne@69 293 * SHA-256 as the integrity check.)
jpayne@69 294 *
jpayne@69 295 * If .version >= 1, read by:
jpayne@69 296 * - lzma_block_decoder()
jpayne@69 297 * - lzma_block_buffer_decode()
jpayne@69 298 *
jpayne@69 299 * Written by (.version is ignored):
jpayne@69 300 * - lzma_block_header_decode() always sets this to false
jpayne@69 301 */
jpayne@69 302 lzma_bool ignore_check;
jpayne@69 303
jpayne@69 304 /** \private Reserved member. */
jpayne@69 305 lzma_bool reserved_bool2;
jpayne@69 306
jpayne@69 307 /** \private Reserved member. */
jpayne@69 308 lzma_bool reserved_bool3;
jpayne@69 309
jpayne@69 310 /** \private Reserved member. */
jpayne@69 311 lzma_bool reserved_bool4;
jpayne@69 312
jpayne@69 313 /** \private Reserved member. */
jpayne@69 314 lzma_bool reserved_bool5;
jpayne@69 315
jpayne@69 316 /** \private Reserved member. */
jpayne@69 317 lzma_bool reserved_bool6;
jpayne@69 318
jpayne@69 319 /** \private Reserved member. */
jpayne@69 320 lzma_bool reserved_bool7;
jpayne@69 321
jpayne@69 322 /** \private Reserved member. */
jpayne@69 323 lzma_bool reserved_bool8;
jpayne@69 324
jpayne@69 325 } lzma_block;
jpayne@69 326
jpayne@69 327
jpayne@69 328 /**
jpayne@69 329 * \brief Decode the Block Header Size field
jpayne@69 330 *
jpayne@69 331 * To decode Block Header using lzma_block_header_decode(), the size of the
jpayne@69 332 * Block Header has to be known and stored into lzma_block.header_size.
jpayne@69 333 * The size can be calculated from the first byte of a Block using this macro.
jpayne@69 334 * Note that if the first byte is 0x00, it indicates beginning of Index; use
jpayne@69 335 * this macro only when the byte is not 0x00.
jpayne@69 336 *
jpayne@69 337 * There is no encoding macro because lzma_block_header_size() and
jpayne@69 338 * lzma_block_header_encode() should be used.
jpayne@69 339 */
jpayne@69 340 #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
jpayne@69 341
jpayne@69 342
jpayne@69 343 /**
jpayne@69 344 * \brief Calculate Block Header Size
jpayne@69 345 *
jpayne@69 346 * Calculate the minimum size needed for the Block Header field using the
jpayne@69 347 * settings specified in the lzma_block structure. Note that it is OK to
jpayne@69 348 * increase the calculated header_size value as long as it is a multiple of
jpayne@69 349 * four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size
jpayne@69 350 * just means that lzma_block_header_encode() will add Header Padding.
jpayne@69 351 *
jpayne@69 352 * \note This doesn't check that all the options are valid i.e. this
jpayne@69 353 * may return LZMA_OK even if lzma_block_header_encode() or
jpayne@69 354 * lzma_block_encoder() would fail. If you want to validate the
jpayne@69 355 * filter chain, consider using lzma_memlimit_encoder() which as
jpayne@69 356 * a side-effect validates the filter chain.
jpayne@69 357 *
jpayne@69 358 * \param block Block options
jpayne@69 359 *
jpayne@69 360 * \return Possible lzma_ret values:
jpayne@69 361 * - LZMA_OK: Size calculated successfully and stored to
jpayne@69 362 * block->header_size.
jpayne@69 363 * - LZMA_OPTIONS_ERROR: Unsupported version, filters or
jpayne@69 364 * filter options.
jpayne@69 365 * - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
jpayne@69 366 */
jpayne@69 367 extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
jpayne@69 368 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 369
jpayne@69 370
jpayne@69 371 /**
jpayne@69 372 * \brief Encode Block Header
jpayne@69 373 *
jpayne@69 374 * The caller must have calculated the size of the Block Header already with
jpayne@69 375 * lzma_block_header_size(). If a value larger than the one calculated by
jpayne@69 376 * lzma_block_header_size() is used, the Block Header will be padded to the
jpayne@69 377 * specified size.
jpayne@69 378 *
jpayne@69 379 * \param block Block options to be encoded.
jpayne@69 380 * \param[out] out Beginning of the output buffer. This must be
jpayne@69 381 * at least block->header_size bytes.
jpayne@69 382 *
jpayne@69 383 * \return Possible lzma_ret values:
jpayne@69 384 * - LZMA_OK: Encoding was successful. block->header_size
jpayne@69 385 * bytes were written to output buffer.
jpayne@69 386 * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
jpayne@69 387 * - LZMA_PROG_ERROR: Invalid arguments, for example
jpayne@69 388 * block->header_size is invalid or block->filters is NULL.
jpayne@69 389 */
jpayne@69 390 extern LZMA_API(lzma_ret) lzma_block_header_encode(
jpayne@69 391 const lzma_block *block, uint8_t *out)
jpayne@69 392 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 393
jpayne@69 394
jpayne@69 395 /**
jpayne@69 396 * \brief Decode Block Header
jpayne@69 397 *
jpayne@69 398 * block->version should (usually) be set to the highest value supported
jpayne@69 399 * by the application. If the application sets block->version to a value
jpayne@69 400 * higher than supported by the current liblzma version, this function will
jpayne@69 401 * downgrade block->version to the highest value supported by it. Thus one
jpayne@69 402 * should check the value of block->version after calling this function if
jpayne@69 403 * block->version was set to a non-zero value and the application doesn't
jpayne@69 404 * otherwise know that the liblzma version being used is new enough to
jpayne@69 405 * support the specified block->version.
jpayne@69 406 *
jpayne@69 407 * The size of the Block Header must have already been decoded with
jpayne@69 408 * lzma_block_header_size_decode() macro and stored to block->header_size.
jpayne@69 409 *
jpayne@69 410 * The integrity check type from Stream Header must have been stored
jpayne@69 411 * to block->check.
jpayne@69 412 *
jpayne@69 413 * block->filters must have been allocated, but they don't need to be
jpayne@69 414 * initialized (possible existing filter options are not freed).
jpayne@69 415 *
jpayne@69 416 * \param[out] block Destination for Block options
jpayne@69 417 * \param allocator lzma_allocator for custom allocator functions.
jpayne@69 418 * Set to NULL to use malloc() (and also free()
jpayne@69 419 * if an error occurs).
jpayne@69 420 * \param in Beginning of the input buffer. This must be
jpayne@69 421 * at least block->header_size bytes.
jpayne@69 422 *
jpayne@69 423 * \return Possible lzma_ret values:
jpayne@69 424 * - LZMA_OK: Decoding was successful. block->header_size
jpayne@69 425 * bytes were read from the input buffer.
jpayne@69 426 * - LZMA_OPTIONS_ERROR: The Block Header specifies some
jpayne@69 427 * unsupported options such as unsupported filters. This can
jpayne@69 428 * happen also if block->version was set to a too low value
jpayne@69 429 * compared to what would be required to properly represent
jpayne@69 430 * the information stored in the Block Header.
jpayne@69 431 * - LZMA_DATA_ERROR: Block Header is corrupt, for example,
jpayne@69 432 * the CRC32 doesn't match.
jpayne@69 433 * - LZMA_PROG_ERROR: Invalid arguments, for example
jpayne@69 434 * block->header_size is invalid or block->filters is NULL.
jpayne@69 435 */
jpayne@69 436 extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block,
jpayne@69 437 const lzma_allocator *allocator, const uint8_t *in)
jpayne@69 438 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 439
jpayne@69 440
jpayne@69 441 /**
jpayne@69 442 * \brief Validate and set Compressed Size according to Unpadded Size
jpayne@69 443 *
jpayne@69 444 * Block Header stores Compressed Size, but Index has Unpadded Size. If the
jpayne@69 445 * application has already parsed the Index and is now decoding Blocks,
jpayne@69 446 * it can calculate Compressed Size from Unpadded Size. This function does
jpayne@69 447 * exactly that with error checking:
jpayne@69 448 *
jpayne@69 449 * - Compressed Size calculated from Unpadded Size must be positive integer,
jpayne@69 450 * that is, Unpadded Size must be big enough that after Block Header and
jpayne@69 451 * Check fields there's still at least one byte for Compressed Size.
jpayne@69 452 *
jpayne@69 453 * - If Compressed Size was present in Block Header, the new value
jpayne@69 454 * calculated from Unpadded Size is compared against the value
jpayne@69 455 * from Block Header.
jpayne@69 456 *
jpayne@69 457 * \note This function must be called _after_ decoding the Block Header
jpayne@69 458 * field so that it can properly validate Compressed Size if it
jpayne@69 459 * was present in Block Header.
jpayne@69 460 *
jpayne@69 461 * \param block Block options: block->header_size must
jpayne@69 462 * already be set with lzma_block_header_size().
jpayne@69 463 * \param unpadded_size Unpadded Size from the Index field in bytes
jpayne@69 464 *
jpayne@69 465 * \return Possible lzma_ret values:
jpayne@69 466 * - LZMA_OK: block->compressed_size was set successfully.
jpayne@69 467 * - LZMA_DATA_ERROR: unpadded_size is too small compared to
jpayne@69 468 * block->header_size and lzma_check_size(block->check).
jpayne@69 469 * - LZMA_PROG_ERROR: Some values are invalid. For example,
jpayne@69 470 * block->header_size must be a multiple of four and
jpayne@69 471 * between 8 and 1024 inclusive.
jpayne@69 472 */
jpayne@69 473 extern LZMA_API(lzma_ret) lzma_block_compressed_size(
jpayne@69 474 lzma_block *block, lzma_vli unpadded_size)
jpayne@69 475 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 476
jpayne@69 477
jpayne@69 478 /**
jpayne@69 479 * \brief Calculate Unpadded Size
jpayne@69 480 *
jpayne@69 481 * The Index field stores Unpadded Size and Uncompressed Size. The latter
jpayne@69 482 * can be taken directly from the lzma_block structure after coding a Block,
jpayne@69 483 * but Unpadded Size needs to be calculated from Block Header Size,
jpayne@69 484 * Compressed Size, and size of the Check field. This is where this function
jpayne@69 485 * is needed.
jpayne@69 486 *
jpayne@69 487 * \param block Block options: block->header_size must already be
jpayne@69 488 * set with lzma_block_header_size().
jpayne@69 489 *
jpayne@69 490 * \return Unpadded Size on success, or zero on error.
jpayne@69 491 */
jpayne@69 492 extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
jpayne@69 493 lzma_nothrow lzma_attr_pure;
jpayne@69 494
jpayne@69 495
jpayne@69 496 /**
jpayne@69 497 * \brief Calculate the total encoded size of a Block
jpayne@69 498 *
jpayne@69 499 * This is equivalent to lzma_block_unpadded_size() except that the returned
jpayne@69 500 * value includes the size of the Block Padding field.
jpayne@69 501 *
jpayne@69 502 * \param block Block options: block->header_size must already be
jpayne@69 503 * set with lzma_block_header_size().
jpayne@69 504 *
jpayne@69 505 * \return On success, total encoded size of the Block. On error,
jpayne@69 506 * zero is returned.
jpayne@69 507 */
jpayne@69 508 extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block)
jpayne@69 509 lzma_nothrow lzma_attr_pure;
jpayne@69 510
jpayne@69 511
jpayne@69 512 /**
jpayne@69 513 * \brief Initialize .xz Block encoder
jpayne@69 514 *
jpayne@69 515 * Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the
jpayne@69 516 * filter chain supports it), and LZMA_FINISH.
jpayne@69 517 *
jpayne@69 518 * The Block encoder encodes the Block Data, Block Padding, and Check value.
jpayne@69 519 * It does NOT encode the Block Header which can be encoded with
jpayne@69 520 * lzma_block_header_encode().
jpayne@69 521 *
jpayne@69 522 * \param strm Pointer to lzma_stream that is at least initialized
jpayne@69 523 * with LZMA_STREAM_INIT.
jpayne@69 524 * \param block Block options: block->version, block->check,
jpayne@69 525 * and block->filters must have been initialized.
jpayne@69 526 *
jpayne@69 527 * \return Possible lzma_ret values:
jpayne@69 528 * - LZMA_OK: All good, continue with lzma_code().
jpayne@69 529 * - LZMA_MEM_ERROR
jpayne@69 530 * - LZMA_OPTIONS_ERROR
jpayne@69 531 * - LZMA_UNSUPPORTED_CHECK: block->check specifies a Check ID
jpayne@69 532 * that is not supported by this build of liblzma. Initializing
jpayne@69 533 * the encoder failed.
jpayne@69 534 * - LZMA_PROG_ERROR
jpayne@69 535 */
jpayne@69 536 extern LZMA_API(lzma_ret) lzma_block_encoder(
jpayne@69 537 lzma_stream *strm, lzma_block *block)
jpayne@69 538 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 539
jpayne@69 540
jpayne@69 541 /**
jpayne@69 542 * \brief Initialize .xz Block decoder
jpayne@69 543 *
jpayne@69 544 * Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using
jpayne@69 545 * LZMA_FINISH is not required. It is supported only for convenience.
jpayne@69 546 *
jpayne@69 547 * The Block decoder decodes the Block Data, Block Padding, and Check value.
jpayne@69 548 * It does NOT decode the Block Header which can be decoded with
jpayne@69 549 * lzma_block_header_decode().
jpayne@69 550 *
jpayne@69 551 * \param strm Pointer to lzma_stream that is at least initialized
jpayne@69 552 * with LZMA_STREAM_INIT.
jpayne@69 553 * \param block Block options
jpayne@69 554 *
jpayne@69 555 * \return Possible lzma_ret values:
jpayne@69 556 * - LZMA_OK: All good, continue with lzma_code().
jpayne@69 557 * - LZMA_PROG_ERROR
jpayne@69 558 * - LZMA_MEM_ERROR
jpayne@69 559 */
jpayne@69 560 extern LZMA_API(lzma_ret) lzma_block_decoder(
jpayne@69 561 lzma_stream *strm, lzma_block *block)
jpayne@69 562 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 563
jpayne@69 564
jpayne@69 565 /**
jpayne@69 566 * \brief Calculate maximum output size for single-call Block encoding
jpayne@69 567 *
jpayne@69 568 * This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks.
jpayne@69 569 * See the documentation of lzma_stream_buffer_bound().
jpayne@69 570 *
jpayne@69 571 * \param uncompressed_size Size of the data to be encoded with the
jpayne@69 572 * single-call Block encoder.
jpayne@69 573 *
jpayne@69 574 * \return Maximum output size in bytes for single-call Block encoding.
jpayne@69 575 */
jpayne@69 576 extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
jpayne@69 577 lzma_nothrow;
jpayne@69 578
jpayne@69 579
jpayne@69 580 /**
jpayne@69 581 * \brief Single-call .xz Block encoder
jpayne@69 582 *
jpayne@69 583 * In contrast to the multi-call encoder initialized with
jpayne@69 584 * lzma_block_encoder(), this function encodes also the Block Header. This
jpayne@69 585 * is required to make it possible to write appropriate Block Header also
jpayne@69 586 * in case the data isn't compressible, and different filter chain has to be
jpayne@69 587 * used to encode the data in uncompressed form using uncompressed chunks
jpayne@69 588 * of the LZMA2 filter.
jpayne@69 589 *
jpayne@69 590 * When the data isn't compressible, header_size, compressed_size, and
jpayne@69 591 * uncompressed_size are set just like when the data was compressible, but
jpayne@69 592 * it is possible that header_size is too small to hold the filter chain
jpayne@69 593 * specified in block->filters, because that isn't necessarily the filter
jpayne@69 594 * chain that was actually used to encode the data. lzma_block_unpadded_size()
jpayne@69 595 * still works normally, because it doesn't read the filters array.
jpayne@69 596 *
jpayne@69 597 * \param block Block options: block->version, block->check,
jpayne@69 598 * and block->filters must have been initialized.
jpayne@69 599 * \param allocator lzma_allocator for custom allocator functions.
jpayne@69 600 * Set to NULL to use malloc() and free().
jpayne@69 601 * \param in Beginning of the input buffer
jpayne@69 602 * \param in_size Size of the input buffer
jpayne@69 603 * \param[out] out Beginning of the output buffer
jpayne@69 604 * \param[out] out_pos The next byte will be written to out[*out_pos].
jpayne@69 605 * *out_pos is updated only if encoding succeeds.
jpayne@69 606 * \param out_size Size of the out buffer; the first byte into
jpayne@69 607 * which no data is written to is out[out_size].
jpayne@69 608 *
jpayne@69 609 * \return Possible lzma_ret values:
jpayne@69 610 * - LZMA_OK: Encoding was successful.
jpayne@69 611 * - LZMA_BUF_ERROR: Not enough output buffer space.
jpayne@69 612 * - LZMA_UNSUPPORTED_CHECK
jpayne@69 613 * - LZMA_OPTIONS_ERROR
jpayne@69 614 * - LZMA_MEM_ERROR
jpayne@69 615 * - LZMA_DATA_ERROR
jpayne@69 616 * - LZMA_PROG_ERROR
jpayne@69 617 */
jpayne@69 618 extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
jpayne@69 619 lzma_block *block, const lzma_allocator *allocator,
jpayne@69 620 const uint8_t *in, size_t in_size,
jpayne@69 621 uint8_t *out, size_t *out_pos, size_t out_size)
jpayne@69 622 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 623
jpayne@69 624
jpayne@69 625 /**
jpayne@69 626 * \brief Single-call uncompressed .xz Block encoder
jpayne@69 627 *
jpayne@69 628 * This is like lzma_block_buffer_encode() except this doesn't try to
jpayne@69 629 * compress the data and instead encodes the data using LZMA2 uncompressed
jpayne@69 630 * chunks. The required output buffer size can be determined with
jpayne@69 631 * lzma_block_buffer_bound().
jpayne@69 632 *
jpayne@69 633 * Since the data won't be compressed, this function ignores block->filters.
jpayne@69 634 * This function doesn't take lzma_allocator because this function doesn't
jpayne@69 635 * allocate any memory from the heap.
jpayne@69 636 *
jpayne@69 637 * \param block Block options: block->version, block->check,
jpayne@69 638 * and block->filters must have been initialized.
jpayne@69 639 * \param in Beginning of the input buffer
jpayne@69 640 * \param in_size Size of the input buffer
jpayne@69 641 * \param[out] out Beginning of the output buffer
jpayne@69 642 * \param[out] out_pos The next byte will be written to out[*out_pos].
jpayne@69 643 * *out_pos is updated only if encoding succeeds.
jpayne@69 644 * \param out_size Size of the out buffer; the first byte into
jpayne@69 645 * which no data is written to is out[out_size].
jpayne@69 646 *
jpayne@69 647 * \return Possible lzma_ret values:
jpayne@69 648 * - LZMA_OK: Encoding was successful.
jpayne@69 649 * - LZMA_BUF_ERROR: Not enough output buffer space.
jpayne@69 650 * - LZMA_UNSUPPORTED_CHECK
jpayne@69 651 * - LZMA_OPTIONS_ERROR
jpayne@69 652 * - LZMA_MEM_ERROR
jpayne@69 653 * - LZMA_DATA_ERROR
jpayne@69 654 * - LZMA_PROG_ERROR
jpayne@69 655 */
jpayne@69 656 extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
jpayne@69 657 const uint8_t *in, size_t in_size,
jpayne@69 658 uint8_t *out, size_t *out_pos, size_t out_size)
jpayne@69 659 lzma_nothrow lzma_attr_warn_unused_result;
jpayne@69 660
jpayne@69 661
jpayne@69 662 /**
jpayne@69 663 * \brief Single-call .xz Block decoder
jpayne@69 664 *
jpayne@69 665 * This is single-call equivalent of lzma_block_decoder(), and requires that
jpayne@69 666 * the caller has already decoded Block Header and checked its memory usage.
jpayne@69 667 *
jpayne@69 668 * \param block Block options
jpayne@69 669 * \param allocator lzma_allocator for custom allocator functions.
jpayne@69 670 * Set to NULL to use malloc() and free().
jpayne@69 671 * \param in Beginning of the input buffer
jpayne@69 672 * \param in_pos The next byte will be read from in[*in_pos].
jpayne@69 673 * *in_pos is updated only if decoding succeeds.
jpayne@69 674 * \param in_size Size of the input buffer; the first byte that
jpayne@69 675 * won't be read is in[in_size].
jpayne@69 676 * \param[out] out Beginning of the output buffer
jpayne@69 677 * \param[out] out_pos The next byte will be written to out[*out_pos].
jpayne@69 678 * *out_pos is updated only if encoding succeeds.
jpayne@69 679 * \param out_size Size of the out buffer; the first byte into
jpayne@69 680 * which no data is written to is out[out_size].
jpayne@69 681 *
jpayne@69 682 * \return Possible lzma_ret values:
jpayne@69 683 * - LZMA_OK: Decoding was successful.
jpayne@69 684 * - LZMA_OPTIONS_ERROR
jpayne@69 685 * - LZMA_DATA_ERROR
jpayne@69 686 * - LZMA_MEM_ERROR
jpayne@69 687 * - LZMA_BUF_ERROR: Output buffer was too small.
jpayne@69 688 * - LZMA_PROG_ERROR
jpayne@69 689 */
jpayne@69 690 extern LZMA_API(lzma_ret) lzma_block_buffer_decode(
jpayne@69 691 lzma_block *block, const lzma_allocator *allocator,
jpayne@69 692 const uint8_t *in, size_t *in_pos, size_t in_size,
jpayne@69 693 uint8_t *out, size_t *out_pos, size_t out_size)
jpayne@69 694 lzma_nothrow;