2 * \file lzma/stream_flags.h
3 * \brief .lzma Stream Header and Stream tail encoder and decoder
5 * \author Copyright (C) 1999-2006 Igor Pavlov
6 * \author Copyright (C) 2007 Lasse Collin
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
19 #ifndef LZMA_H_INTERNAL
20 # error Never include this file directly. Use <lzma.h> instead.
25 * \brief Size of Stream Header
27 * Magic Bytes (6) + Stream Flags (1) + CRC32 (4)
29 #define LZMA_STREAM_HEADER_SIZE (6 + 1 + 4)
33 * \brief Size of Stream tail
35 * Because Stream Footer already has a defined meaning in the file format
36 * specification, we use Stream tail to denote these two fields:
37 * Stream Flags (1) + Magic Bytes (2)
39 #define LZMA_STREAM_TAIL_SIZE (1 + 2)
43 * Options for encoding and decoding Stream Header and Stream tail
47 * Type of the Check calculated from uncompressed data
49 lzma_check_type check;
52 * True if Block Headers have the CRC32 field. Note that the CRC32
53 * field is always present in the Stream Header.
58 * True if the Stream is a Multi-Block Stream.
65 #define lzma_stream_flags_is_equal(a, b) \
66 ((a).check == (b).check \
67 && (a).has_crc32 == (b).has_crc32 \
68 && (a).is_multi == (b).is_multi)
72 * \brief Encodes Stream Header
74 * Encoding of the Stream Header is done with a single call instead of
75 * first initializing and then doing the actual work with lzma_code().
77 * \param out Beginning of the output buffer
78 * \param out_pos out[*out_pos] is the next write position. This
79 * is updated by the encoder.
80 * \param out_size out[out_size] is the first byte to not write.
81 * \param options Stream Header options to be encoded.
83 * \return - LZMA_OK: Encoding was successful.
84 * - LZMA_PROG_ERROR: Invalid options.
85 * - LZMA_BUF_ERROR: Not enough output buffer space.
87 extern lzma_ret lzma_stream_header_encode(
88 uint8_t *out, const lzma_stream_flags *options);
92 * \brief Encodes Stream tail
94 * \param footer Pointer to a pointer that will hold the
95 * allocated buffer. Caller must free it once
96 * it isn't needed anymore.
97 * \param footer_size Pointer to a variable that will the final size
98 * of the footer buffer.
99 * \param allocator lzma_allocator for custom allocator functions.
100 * Set to NULL to use malloc().
101 * \param options Stream Header options to be encoded.
103 * \return - LZMA_OK: Success; *header and *header_size set.
104 * - LZMA_PROG_ERROR: *options is invalid.
105 * - LZMA_MEM_ERROR: Cannot allocate memory.
107 extern lzma_ret lzma_stream_tail_encode(
108 uint8_t *out, const lzma_stream_flags *options);
112 * \brief Initializes Stream Header decoder
114 * \param strm Pointer to lzma_stream used to pass input data
115 * \param options Target structure for parsed results
117 * \return - LZMA_OK: Successfully initialized
118 * - LZMA_MEM_ERROR: Cannot allocate memory
120 * The actual decoding is done with lzma_code() and freed with lzma_end().
122 extern lzma_ret lzma_stream_header_decoder(
123 lzma_stream *strm, lzma_stream_flags *options);
127 * \brief Initializes Stream tail decoder
129 * \param strm Pointer to lzma_stream used to pass input data
130 * \param options Target structure for parsed results.
131 * \param decode_uncompressed_size
132 * Set to true if the first field to decode is
133 * Uncompressed Size. Set to false if the first
134 * field to decode is Backward Size.
136 * \return - LZMA_OK: Successfully initialized
137 * - LZMA_MEM_ERROR: Cannot allocate memory
139 * The actual decoding is done with lzma_code() and freed with lzma_end().
141 extern lzma_ret lzma_stream_tail_decoder(
142 lzma_stream *strm, lzma_stream_flags *options);