index.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /**
  2. * \file lzma/index.h
  3. * \brief Handling of .xz Index and related information
  4. */
  5. /*
  6. * Author: Lasse Collin
  7. *
  8. * This file has been put into the public domain.
  9. * You can do whatever you want with this file.
  10. *
  11. * See ../lzma.h for information about liblzma as a whole.
  12. */
  13. #ifndef LZMA_H_INTERNAL
  14. # error Never include this file directly. Use <lzma.h> instead.
  15. #endif
  16. /**
  17. * \brief Opaque data type to hold the Index(es) and other information
  18. *
  19. * lzma_index often holds just one .xz Index and possibly the Stream Flags
  20. * of the same Stream and size of the Stream Padding field. However,
  21. * multiple lzma_indexes can be concatenated with lzma_index_cat() and then
  22. * there may be information about multiple Streams in the same lzma_index.
  23. *
  24. * Notes about thread safety: Only one thread may modify lzma_index at
  25. * a time. All functions that take non-const pointer to lzma_index
  26. * modify it. As long as no thread is modifying the lzma_index, getting
  27. * information from the same lzma_index can be done from multiple threads
  28. * at the same time with functions that take a const pointer to
  29. * lzma_index or use lzma_index_iter. The same iterator must be used
  30. * only by one thread at a time, of course, but there can be as many
  31. * iterators for the same lzma_index as needed.
  32. */
  33. typedef struct lzma_index_s lzma_index;
  34. /**
  35. * \brief Iterator to get information about Blocks and Streams
  36. */
  37. typedef struct {
  38. struct {
  39. /**
  40. * \brief Pointer to Stream Flags
  41. *
  42. * This is NULL if Stream Flags have not been set for
  43. * this Stream with lzma_index_stream_flags().
  44. */
  45. const lzma_stream_flags *flags;
  46. const void *reserved_ptr1;
  47. const void *reserved_ptr2;
  48. const void *reserved_ptr3;
  49. /**
  50. * \brief Stream number in the lzma_index
  51. *
  52. * The first Stream is 1.
  53. */
  54. lzma_vli number;
  55. /**
  56. * \brief Number of Blocks in the Stream
  57. *
  58. * If this is zero, the block structure below has
  59. * undefined values.
  60. */
  61. lzma_vli block_count;
  62. /**
  63. * \brief Compressed start offset of this Stream
  64. *
  65. * The offset is relative to the beginning of the lzma_index
  66. * (i.e. usually the beginning of the .xz file).
  67. */
  68. lzma_vli compressed_offset;
  69. /**
  70. * \brief Uncompressed start offset of this Stream
  71. *
  72. * The offset is relative to the beginning of the lzma_index
  73. * (i.e. usually the beginning of the .xz file).
  74. */
  75. lzma_vli uncompressed_offset;
  76. /**
  77. * \brief Compressed size of this Stream
  78. *
  79. * This includes all headers except the possible
  80. * Stream Padding after this Stream.
  81. */
  82. lzma_vli compressed_size;
  83. /**
  84. * \brief Uncompressed size of this Stream
  85. */
  86. lzma_vli uncompressed_size;
  87. /**
  88. * \brief Size of Stream Padding after this Stream
  89. *
  90. * If it hasn't been set with lzma_index_stream_padding(),
  91. * this defaults to zero. Stream Padding is always
  92. * a multiple of four bytes.
  93. */
  94. lzma_vli padding;
  95. lzma_vli reserved_vli1;
  96. lzma_vli reserved_vli2;
  97. lzma_vli reserved_vli3;
  98. lzma_vli reserved_vli4;
  99. } stream;
  100. struct {
  101. /**
  102. * \brief Block number in the file
  103. *
  104. * The first Block is 1.
  105. */
  106. lzma_vli number_in_file;
  107. /**
  108. * \brief Compressed start offset of this Block
  109. *
  110. * This offset is relative to the beginning of the
  111. * lzma_index (i.e. usually the beginning of the .xz file).
  112. * Normally this is where you should seek in the .xz file
  113. * to start decompressing this Block.
  114. */
  115. lzma_vli compressed_file_offset;
  116. /**
  117. * \brief Uncompressed start offset of this Block
  118. *
  119. * This offset is relative to the beginning of the lzma_index
  120. * (i.e. usually the beginning of the .xz file).
  121. *
  122. * When doing random-access reading, it is possible that
  123. * the target offset is not exactly at Block boundary. One
  124. * will need to compare the target offset against
  125. * uncompressed_file_offset or uncompressed_stream_offset,
  126. * and possibly decode and throw away some amount of data
  127. * before reaching the target offset.
  128. */
  129. lzma_vli uncompressed_file_offset;
  130. /**
  131. * \brief Block number in this Stream
  132. *
  133. * The first Block is 1.
  134. */
  135. lzma_vli number_in_stream;
  136. /**
  137. * \brief Compressed start offset of this Block
  138. *
  139. * This offset is relative to the beginning of the Stream
  140. * containing this Block.
  141. */
  142. lzma_vli compressed_stream_offset;
  143. /**
  144. * \brief Uncompressed start offset of this Block
  145. *
  146. * This offset is relative to the beginning of the Stream
  147. * containing this Block.
  148. */
  149. lzma_vli uncompressed_stream_offset;
  150. /**
  151. * \brief Uncompressed size of this Block
  152. *
  153. * You should pass this to the Block decoder if you will
  154. * decode this Block. It will allow the Block decoder to
  155. * validate the uncompressed size.
  156. */
  157. lzma_vli uncompressed_size;
  158. /**
  159. * \brief Unpadded size of this Block
  160. *
  161. * You should pass this to the Block decoder if you will
  162. * decode this Block. It will allow the Block decoder to
  163. * validate the unpadded size.
  164. */
  165. lzma_vli unpadded_size;
  166. /**
  167. * \brief Total compressed size
  168. *
  169. * This includes all headers and padding in this Block.
  170. * This is useful if you need to know how many bytes
  171. * the Block decoder will actually read.
  172. */
  173. lzma_vli total_size;
  174. lzma_vli reserved_vli1;
  175. lzma_vli reserved_vli2;
  176. lzma_vli reserved_vli3;
  177. lzma_vli reserved_vli4;
  178. const void *reserved_ptr1;
  179. const void *reserved_ptr2;
  180. const void *reserved_ptr3;
  181. const void *reserved_ptr4;
  182. } block;
  183. /*
  184. * Internal data which is used to store the state of the iterator.
  185. * The exact format may vary between liblzma versions, so don't
  186. * touch these in any way.
  187. */
  188. union {
  189. const void *p;
  190. size_t s;
  191. lzma_vli v;
  192. } internal[6];
  193. } lzma_index_iter;
  194. /**
  195. * \brief Operation mode for lzma_index_iter_next()
  196. */
  197. typedef enum {
  198. LZMA_INDEX_ITER_ANY = 0,
  199. /**<
  200. * \brief Get the next Block or Stream
  201. *
  202. * Go to the next Block if the current Stream has at least
  203. * one Block left. Otherwise go to the next Stream even if
  204. * it has no Blocks. If the Stream has no Blocks
  205. * (lzma_index_iter.stream.block_count == 0),
  206. * lzma_index_iter.block will have undefined values.
  207. */
  208. LZMA_INDEX_ITER_STREAM = 1,
  209. /**<
  210. * \brief Get the next Stream
  211. *
  212. * Go to the next Stream even if the current Stream has
  213. * unread Blocks left. If the next Stream has at least one
  214. * Block, the iterator will point to the first Block.
  215. * If there are no Blocks, lzma_index_iter.block will have
  216. * undefined values.
  217. */
  218. LZMA_INDEX_ITER_BLOCK = 2,
  219. /**<
  220. * \brief Get the next Block
  221. *
  222. * Go to the next Block if the current Stream has at least
  223. * one Block left. If the current Stream has no Blocks left,
  224. * the next Stream with at least one Block is located and
  225. * the iterator will be made to point to the first Block of
  226. * that Stream.
  227. */
  228. LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3
  229. /**<
  230. * \brief Get the next non-empty Block
  231. *
  232. * This is like LZMA_INDEX_ITER_BLOCK except that it will
  233. * skip Blocks whose Uncompressed Size is zero.
  234. */
  235. } lzma_index_iter_mode;
  236. /**
  237. * \brief Calculate memory usage of lzma_index
  238. *
  239. * On disk, the size of the Index field depends on both the number of Records
  240. * stored and how big values the Records store (due to variable-length integer
  241. * encoding). When the Index is kept in lzma_index structure, the memory usage
  242. * depends only on the number of Records/Blocks stored in the Index(es), and
  243. * in case of concatenated lzma_indexes, the number of Streams. The size in
  244. * RAM is almost always significantly bigger than in the encoded form on disk.
  245. *
  246. * This function calculates an approximate amount of memory needed hold
  247. * the given number of Streams and Blocks in lzma_index structure. This
  248. * value may vary between CPU architectures and also between liblzma versions
  249. * if the internal implementation is modified.
  250. */
  251. extern LZMA_API(uint64_t) lzma_index_memusage(
  252. lzma_vli streams, lzma_vli blocks) lzma_nothrow;
  253. /**
  254. * \brief Calculate the memory usage of an existing lzma_index
  255. *
  256. * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i),
  257. * lzma_index_block_count(i)).
  258. */
  259. extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
  260. lzma_nothrow;
  261. /**
  262. * \brief Allocate and initialize a new lzma_index structure
  263. *
  264. * \return On success, a pointer to an empty initialized lzma_index is
  265. * returned. If allocation fails, NULL is returned.
  266. */
  267. extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator)
  268. lzma_nothrow;
  269. /**
  270. * \brief Deallocate lzma_index
  271. *
  272. * If i is NULL, this does nothing.
  273. */
  274. extern LZMA_API(void) lzma_index_end(
  275. lzma_index *i, const lzma_allocator *allocator) lzma_nothrow;
  276. /**
  277. * \brief Add a new Block to lzma_index
  278. *
  279. * \param i Pointer to a lzma_index structure
  280. * \param allocator Pointer to lzma_allocator, or NULL to
  281. * use malloc()
  282. * \param unpadded_size Unpadded Size of a Block. This can be
  283. * calculated with lzma_block_unpadded_size()
  284. * after encoding or decoding the Block.
  285. * \param uncompressed_size Uncompressed Size of a Block. This can be
  286. * taken directly from lzma_block structure
  287. * after encoding or decoding the Block.
  288. *
  289. * Appending a new Block does not invalidate iterators. For example,
  290. * if an iterator was pointing to the end of the lzma_index, after
  291. * lzma_index_append() it is possible to read the next Block with
  292. * an existing iterator.
  293. *
  294. * \return - LZMA_OK
  295. * - LZMA_MEM_ERROR
  296. * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
  297. * Stream or size of the Index field would grow too big.
  298. * - LZMA_PROG_ERROR
  299. */
  300. extern LZMA_API(lzma_ret) lzma_index_append(
  301. lzma_index *i, const lzma_allocator *allocator,
  302. lzma_vli unpadded_size, lzma_vli uncompressed_size)
  303. lzma_nothrow lzma_attr_warn_unused_result;
  304. /**
  305. * \brief Set the Stream Flags
  306. *
  307. * Set the Stream Flags of the last (and typically the only) Stream
  308. * in lzma_index. This can be useful when reading information from the
  309. * lzma_index, because to decode Blocks, knowing the integrity check type
  310. * is needed.
  311. *
  312. * The given Stream Flags are copied into internal preallocated structure
  313. * in the lzma_index, thus the caller doesn't need to keep the *stream_flags
  314. * available after calling this function.
  315. *
  316. * \return - LZMA_OK
  317. * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version.
  318. * - LZMA_PROG_ERROR
  319. */
  320. extern LZMA_API(lzma_ret) lzma_index_stream_flags(
  321. lzma_index *i, const lzma_stream_flags *stream_flags)
  322. lzma_nothrow lzma_attr_warn_unused_result;
  323. /**
  324. * \brief Get the types of integrity Checks
  325. *
  326. * If lzma_index_stream_flags() is used to set the Stream Flags for
  327. * every Stream, lzma_index_checks() can be used to get a bitmask to
  328. * indicate which Check types have been used. It can be useful e.g. if
  329. * showing the Check types to the user.
  330. *
  331. * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
  332. */
  333. extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i)
  334. lzma_nothrow lzma_attr_pure;
  335. /**
  336. * \brief Set the amount of Stream Padding
  337. *
  338. * Set the amount of Stream Padding of the last (and typically the only)
  339. * Stream in the lzma_index. This is needed when planning to do random-access
  340. * reading within multiple concatenated Streams.
  341. *
  342. * By default, the amount of Stream Padding is assumed to be zero bytes.
  343. *
  344. * \return - LZMA_OK
  345. * - LZMA_DATA_ERROR: The file size would grow too big.
  346. * - LZMA_PROG_ERROR
  347. */
  348. extern LZMA_API(lzma_ret) lzma_index_stream_padding(
  349. lzma_index *i, lzma_vli stream_padding)
  350. lzma_nothrow lzma_attr_warn_unused_result;
  351. /**
  352. * \brief Get the number of Streams
  353. */
  354. extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i)
  355. lzma_nothrow lzma_attr_pure;
  356. /**
  357. * \brief Get the number of Blocks
  358. *
  359. * This returns the total number of Blocks in lzma_index. To get number
  360. * of Blocks in individual Streams, use lzma_index_iter.
  361. */
  362. extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i)
  363. lzma_nothrow lzma_attr_pure;
  364. /**
  365. * \brief Get the size of the Index field as bytes
  366. *
  367. * This is needed to verify the Backward Size field in the Stream Footer.
  368. */
  369. extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
  370. lzma_nothrow lzma_attr_pure;
  371. /**
  372. * \brief Get the total size of the Stream
  373. *
  374. * If multiple lzma_indexes have been combined, this works as if the Blocks
  375. * were in a single Stream. This is useful if you are going to combine
  376. * Blocks from multiple Streams into a single new Stream.
  377. */
  378. extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
  379. lzma_nothrow lzma_attr_pure;
  380. /**
  381. * \brief Get the total size of the Blocks
  382. *
  383. * This doesn't include the Stream Header, Stream Footer, Stream Padding,
  384. * or Index fields.
  385. */
  386. extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
  387. lzma_nothrow lzma_attr_pure;
  388. /**
  389. * \brief Get the total size of the file
  390. *
  391. * When no lzma_indexes have been combined with lzma_index_cat() and there is
  392. * no Stream Padding, this function is identical to lzma_index_stream_size().
  393. * If multiple lzma_indexes have been combined, this includes also the headers
  394. * of each separate Stream and the possible Stream Padding fields.
  395. */
  396. extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
  397. lzma_nothrow lzma_attr_pure;
  398. /**
  399. * \brief Get the uncompressed size of the file
  400. */
  401. extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
  402. lzma_nothrow lzma_attr_pure;
  403. /**
  404. * \brief Initialize an iterator
  405. *
  406. * \param iter Pointer to a lzma_index_iter structure
  407. * \param i lzma_index to which the iterator will be associated
  408. *
  409. * This function associates the iterator with the given lzma_index, and calls
  410. * lzma_index_iter_rewind() on the iterator.
  411. *
  412. * This function doesn't allocate any memory, thus there is no
  413. * lzma_index_iter_end(). The iterator is valid as long as the
  414. * associated lzma_index is valid, that is, until lzma_index_end() or
  415. * using it as source in lzma_index_cat(). Specifically, lzma_index doesn't
  416. * become invalid if new Blocks are added to it with lzma_index_append() or
  417. * if it is used as the destination in lzma_index_cat().
  418. *
  419. * It is safe to make copies of an initialized lzma_index_iter, for example,
  420. * to easily restart reading at some particular position.
  421. */
  422. extern LZMA_API(void) lzma_index_iter_init(
  423. lzma_index_iter *iter, const lzma_index *i) lzma_nothrow;
  424. /**
  425. * \brief Rewind the iterator
  426. *
  427. * Rewind the iterator so that next call to lzma_index_iter_next() will
  428. * return the first Block or Stream.
  429. */
  430. extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter)
  431. lzma_nothrow;
  432. /**
  433. * \brief Get the next Block or Stream
  434. *
  435. * \param iter Iterator initialized with lzma_index_iter_init()
  436. * \param mode Specify what kind of information the caller wants
  437. * to get. See lzma_index_iter_mode for details.
  438. *
  439. * \return If next Block or Stream matching the mode was found, *iter
  440. * is updated and this function returns false. If no Block or
  441. * Stream matching the mode is found, *iter is not modified
  442. * and this function returns true. If mode is set to an unknown
  443. * value, *iter is not modified and this function returns true.
  444. */
  445. extern LZMA_API(lzma_bool) lzma_index_iter_next(
  446. lzma_index_iter *iter, lzma_index_iter_mode mode)
  447. lzma_nothrow lzma_attr_warn_unused_result;
  448. /**
  449. * \brief Locate a Block
  450. *
  451. * If it is possible to seek in the .xz file, it is possible to parse
  452. * the Index field(s) and use lzma_index_iter_locate() to do random-access
  453. * reading with granularity of Block size.
  454. *
  455. * \param iter Iterator that was earlier initialized with
  456. * lzma_index_iter_init().
  457. * \param target Uncompressed target offset which the caller would
  458. * like to locate from the Stream
  459. *
  460. * If the target is smaller than the uncompressed size of the Stream (can be
  461. * checked with lzma_index_uncompressed_size()):
  462. * - Information about the Stream and Block containing the requested
  463. * uncompressed offset is stored into *iter.
  464. * - Internal state of the iterator is adjusted so that
  465. * lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
  466. * - This function returns false.
  467. *
  468. * If target is greater than the uncompressed size of the Stream, *iter
  469. * is not modified, and this function returns true.
  470. */
  471. extern LZMA_API(lzma_bool) lzma_index_iter_locate(
  472. lzma_index_iter *iter, lzma_vli target) lzma_nothrow;
  473. /**
  474. * \brief Concatenate lzma_indexes
  475. *
  476. * Concatenating lzma_indexes is useful when doing random-access reading in
  477. * multi-Stream .xz file, or when combining multiple Streams into single
  478. * Stream.
  479. *
  480. * \param dest lzma_index after which src is appended
  481. * \param src lzma_index to be appended after dest. If this
  482. * function succeeds, the memory allocated for src
  483. * is freed or moved to be part of dest, and all
  484. * iterators pointing to src will become invalid.
  485. * \param allocator Custom memory allocator; can be NULL to use
  486. * malloc() and free().
  487. *
  488. * \return - LZMA_OK: lzma_indexes were concatenated successfully.
  489. * src is now a dangling pointer.
  490. * - LZMA_DATA_ERROR: *dest would grow too big.
  491. * - LZMA_MEM_ERROR
  492. * - LZMA_PROG_ERROR
  493. */
  494. extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src,
  495. const lzma_allocator *allocator)
  496. lzma_nothrow lzma_attr_warn_unused_result;
  497. /**
  498. * \brief Duplicate lzma_index
  499. *
  500. * \return A copy of the lzma_index, or NULL if memory allocation failed.
  501. */
  502. extern LZMA_API(lzma_index *) lzma_index_dup(
  503. const lzma_index *i, const lzma_allocator *allocator)
  504. lzma_nothrow lzma_attr_warn_unused_result;
  505. /**
  506. * \brief Initialize .xz Index encoder
  507. *
  508. * \param strm Pointer to properly prepared lzma_stream
  509. * \param i Pointer to lzma_index which should be encoded.
  510. *
  511. * The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
  512. * It is enough to use only one of them (you can choose freely).
  513. *
  514. * \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
  515. * - LZMA_MEM_ERROR
  516. * - LZMA_PROG_ERROR
  517. */
  518. extern LZMA_API(lzma_ret) lzma_index_encoder(
  519. lzma_stream *strm, const lzma_index *i)
  520. lzma_nothrow lzma_attr_warn_unused_result;
  521. /**
  522. * \brief Initialize .xz Index decoder
  523. *
  524. * \param strm Pointer to properly prepared lzma_stream
  525. * \param i The decoded Index will be made available via
  526. * this pointer. Initially this function will
  527. * set *i to NULL (the old value is ignored). If
  528. * decoding succeeds (lzma_code() returns
  529. * LZMA_STREAM_END), *i will be set to point
  530. * to a new lzma_index, which the application
  531. * has to later free with lzma_index_end().
  532. * \param memlimit How much memory the resulting lzma_index is
  533. * allowed to require. liblzma 5.2.3 and earlier
  534. * don't allow 0 here and return LZMA_PROG_ERROR;
  535. * later versions treat 0 as if 1 had been specified.
  536. *
  537. * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
  538. * There is no need to use LZMA_FINISH, but it's allowed because it may
  539. * simplify certain types of applications.
  540. *
  541. * \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
  542. * - LZMA_MEM_ERROR
  543. * - LZMA_PROG_ERROR
  544. *
  545. * liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here
  546. * but that error code has never been possible from this
  547. * initialization function.
  548. */
  549. extern LZMA_API(lzma_ret) lzma_index_decoder(
  550. lzma_stream *strm, lzma_index **i, uint64_t memlimit)
  551. lzma_nothrow lzma_attr_warn_unused_result;
  552. /**
  553. * \brief Single-call .xz Index encoder
  554. *
  555. * \param i lzma_index to be encoded
  556. * \param out Beginning of the output buffer
  557. * \param out_pos The next byte will be written to out[*out_pos].
  558. * *out_pos is updated only if encoding succeeds.
  559. * \param out_size Size of the out buffer; the first byte into
  560. * which no data is written to is out[out_size].
  561. *
  562. * \return - LZMA_OK: Encoding was successful.
  563. * - LZMA_BUF_ERROR: Output buffer is too small. Use
  564. * lzma_index_size() to find out how much output
  565. * space is needed.
  566. * - LZMA_PROG_ERROR
  567. *
  568. * \note This function doesn't take allocator argument since all
  569. * the internal data is allocated on stack.
  570. */
  571. extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
  572. uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
  573. /**
  574. * \brief Single-call .xz Index decoder
  575. *
  576. * \param i If decoding succeeds, *i will point to a new
  577. * lzma_index, which the application has to
  578. * later free with lzma_index_end(). If an error
  579. * occurs, *i will be NULL. The old value of *i
  580. * is always ignored and thus doesn't need to be
  581. * initialized by the caller.
  582. * \param memlimit Pointer to how much memory the resulting
  583. * lzma_index is allowed to require. The value
  584. * pointed by this pointer is modified if and only
  585. * if LZMA_MEMLIMIT_ERROR is returned.
  586. * \param allocator Pointer to lzma_allocator, or NULL to use malloc()
  587. * \param in Beginning of the input buffer
  588. * \param in_pos The next byte will be read from in[*in_pos].
  589. * *in_pos is updated only if decoding succeeds.
  590. * \param in_size Size of the input buffer; the first byte that
  591. * won't be read is in[in_size].
  592. *
  593. * \return - LZMA_OK: Decoding was successful.
  594. * - LZMA_MEM_ERROR
  595. * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
  596. * The minimum required memlimit value was stored to *memlimit.
  597. * - LZMA_DATA_ERROR
  598. * - LZMA_PROG_ERROR
  599. */
  600. extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
  601. uint64_t *memlimit, const lzma_allocator *allocator,
  602. const uint8_t *in, size_t *in_pos, size_t in_size)
  603. lzma_nothrow;