liblzma: Improve documentation in index.h
[xz/debian.git] / src / liblzma / api / lzma / index.h
blob64ec83509ff1f62aeb602643b452f375796704f6
1 /**
2 * \file lzma/index.h
3 * \brief Handling of .xz Index and related information
4 * \note Never include this file directly. Use <lzma.h> instead.
6 * See ../lzma.h for information about liblzma as a whole.
7 */
9 /*
10 * Author: Lasse Collin
12 * This file has been put into the public domain.
13 * You can do whatever you want with this file.
16 #ifndef LZMA_H_INTERNAL
17 # error Never include this file directly. Use <lzma.h> instead.
18 #endif
21 /**
22 * \brief Opaque data type to hold the Index(es) and other information
24 * lzma_index often holds just one .xz Index and possibly the Stream Flags
25 * of the same Stream and size of the Stream Padding field. However,
26 * multiple lzma_indexes can be concatenated with lzma_index_cat() and then
27 * there may be information about multiple Streams in the same lzma_index.
29 * Notes about thread safety: Only one thread may modify lzma_index at
30 * a time. All functions that take non-const pointer to lzma_index
31 * modify it. As long as no thread is modifying the lzma_index, getting
32 * information from the same lzma_index can be done from multiple threads
33 * at the same time with functions that take a const pointer to
34 * lzma_index or use lzma_index_iter. The same iterator must be used
35 * only by one thread at a time, of course, but there can be as many
36 * iterators for the same lzma_index as needed.
38 typedef struct lzma_index_s lzma_index;
41 /**
42 * \brief Iterator to get information about Blocks and Streams
44 typedef struct {
45 struct {
46 /**
47 * \brief Pointer to Stream Flags
49 * This is NULL if Stream Flags have not been set for
50 * this Stream with lzma_index_stream_flags().
52 const lzma_stream_flags *flags;
54 /** \private Reserved field. */
55 const void *reserved_ptr1;
57 /** \private Reserved field. */
58 const void *reserved_ptr2;
60 /** \private Reserved field. */
61 const void *reserved_ptr3;
63 /**
64 * \brief Stream number in the lzma_index
66 * The first Stream is 1.
68 lzma_vli number;
70 /**
71 * \brief Number of Blocks in the Stream
73 * If this is zero, the block structure below has
74 * undefined values.
76 lzma_vli block_count;
78 /**
79 * \brief Compressed start offset of this Stream
81 * The offset is relative to the beginning of the lzma_index
82 * (i.e. usually the beginning of the .xz file).
84 lzma_vli compressed_offset;
86 /**
87 * \brief Uncompressed start offset of this Stream
89 * The offset is relative to the beginning of the lzma_index
90 * (i.e. usually the beginning of the .xz file).
92 lzma_vli uncompressed_offset;
94 /**
95 * \brief Compressed size of this Stream
97 * This includes all headers except the possible
98 * Stream Padding after this Stream.
100 lzma_vli compressed_size;
103 * \brief Uncompressed size of this Stream
105 lzma_vli uncompressed_size;
108 * \brief Size of Stream Padding after this Stream
110 * If it hasn't been set with lzma_index_stream_padding(),
111 * this defaults to zero. Stream Padding is always
112 * a multiple of four bytes.
114 lzma_vli padding;
117 /** \private Reserved field. */
118 lzma_vli reserved_vli1;
120 /** \private Reserved field. */
121 lzma_vli reserved_vli2;
123 /** \private Reserved field. */
124 lzma_vli reserved_vli3;
126 /** \private Reserved field. */
127 lzma_vli reserved_vli4;
128 } stream;
130 struct {
132 * \brief Block number in the file
134 * The first Block is 1.
136 lzma_vli number_in_file;
139 * \brief Compressed start offset of this Block
141 * This offset is relative to the beginning of the
142 * lzma_index (i.e. usually the beginning of the .xz file).
143 * Normally this is where you should seek in the .xz file
144 * to start decompressing this Block.
146 lzma_vli compressed_file_offset;
149 * \brief Uncompressed start offset of this Block
151 * This offset is relative to the beginning of the lzma_index
152 * (i.e. usually the beginning of the .xz file).
154 * When doing random-access reading, it is possible that
155 * the target offset is not exactly at Block boundary. One
156 * will need to compare the target offset against
157 * uncompressed_file_offset or uncompressed_stream_offset,
158 * and possibly decode and throw away some amount of data
159 * before reaching the target offset.
161 lzma_vli uncompressed_file_offset;
164 * \brief Block number in this Stream
166 * The first Block is 1.
168 lzma_vli number_in_stream;
171 * \brief Compressed start offset of this Block
173 * This offset is relative to the beginning of the Stream
174 * containing this Block.
176 lzma_vli compressed_stream_offset;
179 * \brief Uncompressed start offset of this Block
181 * This offset is relative to the beginning of the Stream
182 * containing this Block.
184 lzma_vli uncompressed_stream_offset;
187 * \brief Uncompressed size of this Block
189 * You should pass this to the Block decoder if you will
190 * decode this Block. It will allow the Block decoder to
191 * validate the uncompressed size.
193 lzma_vli uncompressed_size;
196 * \brief Unpadded size of this Block
198 * You should pass this to the Block decoder if you will
199 * decode this Block. It will allow the Block decoder to
200 * validate the unpadded size.
202 lzma_vli unpadded_size;
205 * \brief Total compressed size
207 * This includes all headers and padding in this Block.
208 * This is useful if you need to know how many bytes
209 * the Block decoder will actually read.
211 lzma_vli total_size;
213 /** \private Reserved field. */
214 lzma_vli reserved_vli1;
216 /** \private Reserved field. */
217 lzma_vli reserved_vli2;
219 /** \private Reserved field. */
220 lzma_vli reserved_vli3;
222 /** \private Reserved field. */
223 lzma_vli reserved_vli4;
225 /** \private Reserved field. */
226 const void *reserved_ptr1;
228 /** \private Reserved field. */
229 const void *reserved_ptr2;
231 /** \private Reserved field. */
232 const void *reserved_ptr3;
234 /** \private Reserved field. */
235 const void *reserved_ptr4;
236 } block;
238 /**
239 * \private Internal struct.
241 * Internal data which is used to store the state of the iterator.
242 * The exact format may vary between liblzma versions, so don't
243 * touch these in any way.
245 union {
246 /** \private Internal field. */
247 const void *p;
249 /** \private Internal field. */
250 size_t s;
252 /** \private Internal field. */
253 lzma_vli v;
254 } internal[6];
255 } lzma_index_iter;
259 * \brief Operation mode for lzma_index_iter_next()
261 typedef enum {
262 LZMA_INDEX_ITER_ANY = 0,
263 /**<
264 * \brief Get the next Block or Stream
266 * Go to the next Block if the current Stream has at least
267 * one Block left. Otherwise go to the next Stream even if
268 * it has no Blocks. If the Stream has no Blocks
269 * (lzma_index_iter.stream.block_count == 0),
270 * lzma_index_iter.block will have undefined values.
273 LZMA_INDEX_ITER_STREAM = 1,
274 /**<
275 * \brief Get the next Stream
277 * Go to the next Stream even if the current Stream has
278 * unread Blocks left. If the next Stream has at least one
279 * Block, the iterator will point to the first Block.
280 * If there are no Blocks, lzma_index_iter.block will have
281 * undefined values.
284 LZMA_INDEX_ITER_BLOCK = 2,
285 /**<
286 * \brief Get the next Block
288 * Go to the next Block if the current Stream has at least
289 * one Block left. If the current Stream has no Blocks left,
290 * the next Stream with at least one Block is located and
291 * the iterator will be made to point to the first Block of
292 * that Stream.
295 LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3
296 /**<
297 * \brief Get the next non-empty Block
299 * This is like LZMA_INDEX_ITER_BLOCK except that it will
300 * skip Blocks whose Uncompressed Size is zero.
303 } lzma_index_iter_mode;
307 * \brief Calculate memory usage of lzma_index
309 * On disk, the size of the Index field depends on both the number of Records
310 * stored and the size of the Records (due to variable-length integer
311 * encoding). When the Index is kept in lzma_index structure, the memory usage
312 * depends only on the number of Records/Blocks stored in the Index(es), and
313 * in case of concatenated lzma_indexes, the number of Streams. The size in
314 * RAM is almost always significantly bigger than in the encoded form on disk.
316 * This function calculates an approximate amount of memory needed to hold
317 * the given number of Streams and Blocks in lzma_index structure. This
318 * value may vary between CPU architectures and also between liblzma versions
319 * if the internal implementation is modified.
321 * \param streams Number of Streams
322 * \param blocks Number of Blocks
324 * \return Approximate memory in bytes needed in a lzma_index structure.
326 extern LZMA_API(uint64_t) lzma_index_memusage(
327 lzma_vli streams, lzma_vli blocks) lzma_nothrow;
331 * \brief Calculate the memory usage of an existing lzma_index
333 * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i),
334 * lzma_index_block_count(i)).
336 * \param i Pointer to lzma_index structure
338 * \return Approximate memory in bytes used by the lzma_index structure.
340 extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
341 lzma_nothrow;
345 * \brief Allocate and initialize a new lzma_index structure
347 * \param allocator lzma_allocator for custom allocator functions.
348 * Set to NULL to use malloc() and free().
350 * \return On success, a pointer to an empty initialized lzma_index is
351 * returned. If allocation fails, NULL is returned.
353 extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator)
354 lzma_nothrow;
358 * \brief Deallocate lzma_index
360 * If i is NULL, this does nothing.
362 * \param i Pointer to lzma_index structure to deallocate
363 * \param allocator lzma_allocator for custom allocator functions.
364 * Set to NULL to use malloc() and free().
366 extern LZMA_API(void) lzma_index_end(
367 lzma_index *i, const lzma_allocator *allocator) lzma_nothrow;
371 * \brief Add a new Block to lzma_index
373 * \param i Pointer to a lzma_index structure
374 * \param allocator lzma_allocator for custom allocator
375 * functions. Set to NULL to use malloc()
376 * and free().
377 * \param unpadded_size Unpadded Size of a Block. This can be
378 * calculated with lzma_block_unpadded_size()
379 * after encoding or decoding the Block.
380 * \param uncompressed_size Uncompressed Size of a Block. This can be
381 * taken directly from lzma_block structure
382 * after encoding or decoding the Block.
384 * Appending a new Block does not invalidate iterators. For example,
385 * if an iterator was pointing to the end of the lzma_index, after
386 * lzma_index_append() it is possible to read the next Block with
387 * an existing iterator.
389 * \return Possible lzma_ret values:
390 * - LZMA_OK
391 * - LZMA_MEM_ERROR
392 * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
393 * Stream or size of the Index field would grow too big.
394 * - LZMA_PROG_ERROR
396 extern LZMA_API(lzma_ret) lzma_index_append(
397 lzma_index *i, const lzma_allocator *allocator,
398 lzma_vli unpadded_size, lzma_vli uncompressed_size)
399 lzma_nothrow lzma_attr_warn_unused_result;
403 * \brief Set the Stream Flags
405 * Set the Stream Flags of the last (and typically the only) Stream
406 * in lzma_index. This can be useful when reading information from the
407 * lzma_index, because to decode Blocks, knowing the integrity check type
408 * is needed.
410 * \param i Pointer to lzma_index structure
411 * \param stream_flags Pointer to lzma_stream_flags structure. This
412 * is copied into the internal preallocated
413 * structure, so the caller doesn't need to keep
414 * the flags' data available after calling this
415 * function.
417 * \return Possible lzma_ret values:
418 * - LZMA_OK
419 * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version.
420 * - LZMA_PROG_ERROR
422 extern LZMA_API(lzma_ret) lzma_index_stream_flags(
423 lzma_index *i, const lzma_stream_flags *stream_flags)
424 lzma_nothrow lzma_attr_warn_unused_result;
428 * \brief Get the types of integrity Checks
430 * If lzma_index_stream_flags() is used to set the Stream Flags for
431 * every Stream, lzma_index_checks() can be used to get a bitmask to
432 * indicate which Check types have been used. It can be useful e.g. if
433 * showing the Check types to the user.
435 * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
437 * \param i Pointer to lzma_index structure
439 * \return Bitmask indicating which Check types are used in the lzma_index
441 extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i)
442 lzma_nothrow lzma_attr_pure;
446 * \brief Set the amount of Stream Padding
448 * Set the amount of Stream Padding of the last (and typically the only)
449 * Stream in the lzma_index. This is needed when planning to do random-access
450 * reading within multiple concatenated Streams.
452 * By default, the amount of Stream Padding is assumed to be zero bytes.
454 * \return Possible lzma_ret values:
455 * - LZMA_OK
456 * - LZMA_DATA_ERROR: The file size would grow too big.
457 * - LZMA_PROG_ERROR
459 extern LZMA_API(lzma_ret) lzma_index_stream_padding(
460 lzma_index *i, lzma_vli stream_padding)
461 lzma_nothrow lzma_attr_warn_unused_result;
465 * \brief Get the number of Streams
467 * \param i Pointer to lzma_index structure
469 * \return Number of Streams in the lzma_index
471 extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i)
472 lzma_nothrow lzma_attr_pure;
476 * \brief Get the number of Blocks
478 * This returns the total number of Blocks in lzma_index. To get number
479 * of Blocks in individual Streams, use lzma_index_iter.
481 * \param i Pointer to lzma_index structure
483 * \return Number of blocks in the lzma_index
485 extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i)
486 lzma_nothrow lzma_attr_pure;
490 * \brief Get the size of the Index field as bytes
492 * This is needed to verify the Backward Size field in the Stream Footer.
494 * \param i Pointer to lzma_index structure
496 * \return Size in bytes of the Index
498 extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
499 lzma_nothrow lzma_attr_pure;
503 * \brief Get the total size of the Stream
505 * If multiple lzma_indexes have been combined, this works as if the Blocks
506 * were in a single Stream. This is useful if you are going to combine
507 * Blocks from multiple Streams into a single new Stream.
509 * \param i Pointer to lzma_index structure
511 * \return Size in bytes of the Stream (if all Blocks are combined
512 * into one Stream).
514 extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
515 lzma_nothrow lzma_attr_pure;
519 * \brief Get the total size of the Blocks
521 * This doesn't include the Stream Header, Stream Footer, Stream Padding,
522 * or Index fields.
524 * \param i Pointer to lzma_index structure
526 * \return Size in bytes of all Blocks in the Stream(s)
528 extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
529 lzma_nothrow lzma_attr_pure;
533 * \brief Get the total size of the file
535 * When no lzma_indexes have been combined with lzma_index_cat() and there is
536 * no Stream Padding, this function is identical to lzma_index_stream_size().
537 * If multiple lzma_indexes have been combined, this includes also the headers
538 * of each separate Stream and the possible Stream Padding fields.
540 * \param i Pointer to lzma_index structure
542 * \return Total size of the .xz file in bytes
544 extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
545 lzma_nothrow lzma_attr_pure;
549 * \brief Get the uncompressed size of the file
551 * \param i Pointer to lzma_index structure
553 * \return Size in bytes of the uncompressed data in the file
555 extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
556 lzma_nothrow lzma_attr_pure;
560 * \brief Initialize an iterator
562 * This function associates the iterator with the given lzma_index, and calls
563 * lzma_index_iter_rewind() on the iterator.
565 * This function doesn't allocate any memory, thus there is no
566 * lzma_index_iter_end(). The iterator is valid as long as the
567 * associated lzma_index is valid, that is, until lzma_index_end() or
568 * using it as source in lzma_index_cat(). Specifically, lzma_index doesn't
569 * become invalid if new Blocks are added to it with lzma_index_append() or
570 * if it is used as the destination in lzma_index_cat().
572 * It is safe to make copies of an initialized lzma_index_iter, for example,
573 * to easily restart reading at some particular position.
575 * \param iter Pointer to a lzma_index_iter structure
576 * \param i lzma_index to which the iterator will be associated
578 extern LZMA_API(void) lzma_index_iter_init(
579 lzma_index_iter *iter, const lzma_index *i) lzma_nothrow;
583 * \brief Rewind the iterator
585 * Rewind the iterator so that next call to lzma_index_iter_next() will
586 * return the first Block or Stream.
588 * \param iter Pointer to a lzma_index_iter structure
590 extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter)
591 lzma_nothrow;
595 * \brief Get the next Block or Stream
597 * \param iter Iterator initialized with lzma_index_iter_init()
598 * \param mode Specify what kind of information the caller wants
599 * to get. See lzma_index_iter_mode for details.
601 * \return lzma_bool:
602 * - true if no Block or Stream matching the mode is found.
603 * *iter is not updated (failure).
604 * - false if the next Block or Stream matching the mode was
605 * found. *iter is updated (success).
607 extern LZMA_API(lzma_bool) lzma_index_iter_next(
608 lzma_index_iter *iter, lzma_index_iter_mode mode)
609 lzma_nothrow lzma_attr_warn_unused_result;
613 * \brief Locate a Block
615 * If it is possible to seek in the .xz file, it is possible to parse
616 * the Index field(s) and use lzma_index_iter_locate() to do random-access
617 * reading with granularity of Block size.
619 * If the target is smaller than the uncompressed size of the Stream (can be
620 * checked with lzma_index_uncompressed_size()):
621 * - Information about the Stream and Block containing the requested
622 * uncompressed offset is stored into *iter.
623 * - Internal state of the iterator is adjusted so that
624 * lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
626 * If the target is greater than the uncompressed size of the Stream, *iter
627 * is not modified.
629 * \param iter Iterator that was earlier initialized with
630 * lzma_index_iter_init().
631 * \param target Uncompressed target offset which the caller would
632 * like to locate from the Stream
634 * \return lzma_bool:
635 * - true if the target is greater than or equal to the
636 * uncompressed size of the Stream (failure)
637 * - false if the target is smaller than the uncompressed size
638 * of the Stream (success)
640 extern LZMA_API(lzma_bool) lzma_index_iter_locate(
641 lzma_index_iter *iter, lzma_vli target) lzma_nothrow;
645 * \brief Concatenate lzma_indexes
647 * Concatenating lzma_indexes is useful when doing random-access reading in
648 * multi-Stream .xz file, or when combining multiple Streams into single
649 * Stream.
651 * \param[out] dest lzma_index after which src is appended
652 * \param src lzma_index to be appended after dest. If this
653 * function succeeds, the memory allocated for src
654 * is freed or moved to be part of dest, and all
655 * iterators pointing to src will become invalid.
656 * \param allocator lzma_allocator for custom allocator functions.
657 * Set to NULL to use malloc() and free().
659 * \return Possible lzma_ret values:
660 * - LZMA_OK: lzma_indexes were concatenated successfully.
661 * src is now a dangling pointer.
662 * - LZMA_DATA_ERROR: *dest would grow too big.
663 * - LZMA_MEM_ERROR
664 * - LZMA_PROG_ERROR
666 extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src,
667 const lzma_allocator *allocator)
668 lzma_nothrow lzma_attr_warn_unused_result;
672 * \brief Duplicate lzma_index
674 * \param i Pointer to lzma_index structure to be duplicated
675 * \param allocator lzma_allocator for custom allocator functions.
676 * Set to NULL to use malloc() and free().
678 * \return A copy of the lzma_index, or NULL if memory allocation failed.
680 extern LZMA_API(lzma_index *) lzma_index_dup(
681 const lzma_index *i, const lzma_allocator *allocator)
682 lzma_nothrow lzma_attr_warn_unused_result;
686 * \brief Initialize .xz Index encoder
688 * \param strm Pointer to properly prepared lzma_stream
689 * \param i Pointer to lzma_index which should be encoded.
691 * The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
692 * It is enough to use only one of them (you can choose freely).
694 * \return Possible lzma_ret values:
695 * - LZMA_OK: Initialization succeeded, continue with lzma_code().
696 * - LZMA_MEM_ERROR
697 * - LZMA_PROG_ERROR
699 extern LZMA_API(lzma_ret) lzma_index_encoder(
700 lzma_stream *strm, const lzma_index *i)
701 lzma_nothrow lzma_attr_warn_unused_result;
705 * \brief Initialize .xz Index decoder
707 * \param strm Pointer to properly prepared lzma_stream
708 * \param[out] i The decoded Index will be made available via
709 * this pointer. Initially this function will
710 * set *i to NULL (the old value is ignored). If
711 * decoding succeeds (lzma_code() returns
712 * LZMA_STREAM_END), *i will be set to point
713 * to a new lzma_index, which the application
714 * has to later free with lzma_index_end().
715 * \param memlimit How much memory the resulting lzma_index is
716 * allowed to require. liblzma 5.2.3 and earlier
717 * don't allow 0 here and return LZMA_PROG_ERROR;
718 * later versions treat 0 as if 1 had been specified.
720 * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
721 * There is no need to use LZMA_FINISH, but it's allowed because it may
722 * simplify certain types of applications.
724 * \return Possible lzma_ret values:
725 * - LZMA_OK: Initialization succeeded, continue with lzma_code().
726 * - LZMA_MEM_ERROR
727 * - LZMA_PROG_ERROR
729 * \note liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here
730 * but that error code has never been possible from this
731 * initialization function.
733 extern LZMA_API(lzma_ret) lzma_index_decoder(
734 lzma_stream *strm, lzma_index **i, uint64_t memlimit)
735 lzma_nothrow lzma_attr_warn_unused_result;
739 * \brief Single-call .xz Index encoder
741 * \note This function doesn't take allocator argument since all
742 * the internal data is allocated on stack.
744 * \param i lzma_index to be encoded
745 * \param[out] out Beginning of the output buffer
746 * \param[out] out_pos The next byte will be written to out[*out_pos].
747 * *out_pos is updated only if encoding succeeds.
748 * \param out_size Size of the out buffer; the first byte into
749 * which no data is written to is out[out_size].
751 * \return Possible lzma_ret values:
752 * - LZMA_OK: Encoding was successful.
753 * - LZMA_BUF_ERROR: Output buffer is too small. Use
754 * lzma_index_size() to find out how much output
755 * space is needed.
756 * - LZMA_PROG_ERROR
759 extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
760 uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
764 * \brief Single-call .xz Index decoder
766 * \param[out] i If decoding succeeds, *i will point to a new
767 * lzma_index, which the application has to
768 * later free with lzma_index_end(). If an error
769 * occurs, *i will be NULL. The old value of *i
770 * is always ignored and thus doesn't need to be
771 * initialized by the caller.
772 * \param[out] memlimit Pointer to how much memory the resulting
773 * lzma_index is allowed to require. The value
774 * pointed by this pointer is modified if and only
775 * if LZMA_MEMLIMIT_ERROR is returned.
776 * \param allocator lzma_allocator for custom allocator functions.
777 * Set to NULL to use malloc() and free().
778 * \param in Beginning of the input buffer
779 * \param in_pos The next byte will be read from in[*in_pos].
780 * *in_pos is updated only if decoding succeeds.
781 * \param in_size Size of the input buffer; the first byte that
782 * won't be read is in[in_size].
784 * \return Possible lzma_ret values:
785 * - LZMA_OK: Decoding was successful.
786 * - LZMA_MEM_ERROR
787 * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
788 * The minimum required memlimit value was stored to *memlimit.
789 * - LZMA_DATA_ERROR
790 * - LZMA_PROG_ERROR
792 extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
793 uint64_t *memlimit, const lzma_allocator *allocator,
794 const uint8_t *in, size_t *in_pos, size_t in_size)
795 lzma_nothrow;
799 * \brief Initialize a .xz file information decoder
801 * This decoder decodes the Stream Header, Stream Footer, Index, and
802 * Stream Padding field(s) from the input .xz file and stores the resulting
803 * combined index in *dest_index. This information can be used to get the
804 * uncompressed file size with lzma_index_uncompressed_size(*dest_index) or,
805 * for example, to implement random access reading by locating the Blocks
806 * in the Streams.
808 * To get the required information from the .xz file, lzma_code() may ask
809 * the application to seek in the input file by returning LZMA_SEEK_NEEDED
810 * and having the target file position specified in lzma_stream.seek_pos.
811 * The number of seeks required depends on the input file and how big buffers
812 * the application provides. When possible, the decoder will seek backward
813 * and forward in the given buffer to avoid useless seek requests. Thus, if
814 * the application provides the whole file at once, no external seeking will
815 * be required (that is, lzma_code() won't return LZMA_SEEK_NEEDED).
817 * The value in lzma_stream.total_in can be used to estimate how much data
818 * liblzma had to read to get the file information. However, due to seeking
819 * and the way total_in is updated, the value of total_in will be somewhat
820 * inaccurate (a little too big). Thus, total_in is a good estimate but don't
821 * expect to see the same exact value for the same file if you change the
822 * input buffer size or switch to a different liblzma version.
824 * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
825 * You only need to use LZMA_RUN; LZMA_FINISH is only supported because it
826 * might be convenient for some applications. If you use LZMA_FINISH and if
827 * lzma_code() asks the application to seek, remember to reset `action' back
828 * to LZMA_RUN unless you hit the end of the file again.
830 * Possible return values from lzma_code():
831 * - LZMA_OK: All OK so far, more input needed
832 * - LZMA_SEEK_NEEDED: Provide more input starting from the absolute
833 * file position strm->seek_pos
834 * - LZMA_STREAM_END: Decoding was successful, *dest_index has been set
835 * - LZMA_FORMAT_ERROR: The input file is not in the .xz format (the
836 * expected magic bytes were not found from the beginning of the file)
837 * - LZMA_OPTIONS_ERROR: File looks valid but contains headers that aren't
838 * supported by this version of liblzma
839 * - LZMA_DATA_ERROR: File is corrupt
840 * - LZMA_BUF_ERROR
841 * - LZMA_MEM_ERROR
842 * - LZMA_MEMLIMIT_ERROR
843 * - LZMA_PROG_ERROR
845 * \param strm Pointer to a properly prepared lzma_stream
846 * \param[out] dest_index Pointer to a pointer where the decoder will put
847 * the decoded lzma_index. The old value
848 * of *dest_index is ignored (not freed).
849 * \param memlimit How much memory the resulting lzma_index is
850 * allowed to require. Use UINT64_MAX to
851 * effectively disable the limiter.
852 * \param file_size Size of the input .xz file
854 * \return Possible lzma_ret values:
855 * - LZMA_OK
856 * - LZMA_MEM_ERROR
857 * - LZMA_PROG_ERROR
859 extern LZMA_API(lzma_ret) lzma_file_info_decoder(
860 lzma_stream *strm, lzma_index **dest_index,
861 uint64_t memlimit, uint64_t file_size)
862 lzma_nothrow;