block.h 25 KB

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