aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api/lzma/stream.h
blob: 346bdd17fcf85942dcf2024a6bfdd355555301b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
 * \file        lzma/stream.h
 * \brief       .lzma Stream handling
 *
 * \author      Copyright (C) 1999-2006 Igor Pavlov
 * \author      Copyright (C) 2007 Lasse Collin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#ifndef LZMA_H_INTERNAL
#	error Never include this file directly. Use <lzma.h> instead.
#endif


/**
 * \brief       Options for .lzma Stream encoder
 */
typedef struct {
	/**
	 * \brief       Type of integrity Check
	 *
	 * The type of the integrity Check is stored into Stream Header
	 * and Stream Footer. The same Check is used for all Blocks in
	 * the Stream.
	 */
	lzma_check_type check;

	/**
	 * \brief       Precense of CRC32 of the Block Header
	 *
	 * Set this to true if CRC32 of every Block Header should be
	 * calculated and stored in the Block Header. This is recommended.
	 *
	 * This setting is stored into Stream Header and Stream Footer.
	 */
	lzma_bool has_crc32;

	/**
	 * \brief       Uncompressed Size in bytes
	 *
	 * This is somewhat advanced feature. Most users want to set this to
	 * LZMA_VLI_VALUE_UNKNOWN to indicate unknown Uncompressed Size.
	 *
	 * If the Uncompressed Size of the Stream being encoded is known,
	 * it can be stored to the beginning of the Stream. The details
	 * differ for Single-Block and Multi-Block Streams:
	 *  - With Single-Block Streams, the Uncompressed Size is stored to
	 *    the Block Header and End of Payload Marker is omitted.
	 *  - With Multi-Block Streams, the Uncompressed Size is stored to
	 *    the Header Metadata Block. The Uncompressed Size of the Blocks
	 *    will be unknown, because liblzma cannot predict how the
	 *    application is going to split the data in Blocks.
	 */
	lzma_vli uncompressed_size;

	/**
	 * \brief       Alignment of the beginning of the Stream
	 *
	 * Certain filters handle data in bigger chunks than single bytes.
	 * This affects two things:
	 *   - Performance: aligned memory access is usually faster.
	 *   - Further compression ratio in custom file formats: if you
	 *     encode multiple Blocks with some non-compression filter
	 *     such as LZMA_FILTER_POWERPC, it is a good idea to keep
	 *     the inter-Block alignment correct to maximize compression
	 *     ratio when all these Blocks are finally compressed as a
	 *     single step.
	 *
	 * Usually the Stream is stored into its own file, thus
	 * the alignment is usually zero.
	 */
	uint32_t alignment;

	/**
	 * \brief       Array of filters used to encode Data Blocks
	 *
	 * There can be at maximum of seven filters. The end of the array is
	 * marked with .id = LZMA_VLI_VALUE_UNKNOWN. (That's why the array
	 * has eight members.) Minimum number of filters is zero; in that
	 * case, an implicit Copy filter is used.
	 */
	lzma_options_filter filters[8];

	/**
	 * \brief       Array of filters used to encode Metadata Blocks
	 *
	 * This is like filters[] but for Metadata Blocks. If Metadata
	 * Blocks are compressed, they usually are compressed with
	 * settings that require only little memory to uncompress e.g.
	 * LZMA with 64 KiB dictionary.
	 *
	 * \todo        Recommend a preset.
	 *
	 * When liblzma sees that the Metadata Block would be very small
	 * even in uncompressed form, it is not compressed no matter
	 * what filter have been set here. This is to avoid possibly
	 * increasing the size of the Metadata Block with bad compression,
	 * and to avoid useless overhead of filters in uncompression phase.
	 */
	lzma_options_filter metadata_filters[8];

	/**
	 * \brief       Extra information in the Header Metadata Block
	 */
	const lzma_extra *header;

	/**
	 * \brief       Extra information in the Footer Metadata Block
	 *
	 * It is enough to set this pointer any time before calling
	 * lzma_code() with LZMA_FINISH as the second argument.
	 */
	const lzma_extra *footer;

} lzma_options_stream;


/**
 * \brief       Initializes Single-Block .lzma Stream encoder
 *
 * This is the function that most developers are looking for. :-) It
 * compresses using the specified options without storing any extra
 * information.
 *
 * \todo        Describe that is_metadata is ignored, maybe something else.
 */
extern lzma_ret lzma_stream_encoder_single(
		lzma_stream *strm, const lzma_options_stream *options);


/**
 * \brief       Initializes Multi-Block .lzma Stream encoder
 *
 */
extern lzma_ret lzma_stream_encoder_multi(
		lzma_stream *strm, const lzma_options_stream *options);


/**
 * \brief       Initializes decoder for .lzma Stream
 *
 * \param       strm        Pointer to propertily prepared lzma_stream
 * \param       header      Pointer to hold a pointer to Extra Records read
 *                          from the Header Metadata Block. Use NULL if
 *                          you don't care about Extra Records.
 * \param       footer      Same as header, but for Footer Metadata Block.
 *
 * \return      - LZMA_OK: Initialization was successful.
 *              - LZMA_MEM_ERROR: Cannot allocate memory.
 *
 * If header and/or footer are not NULL, *header and/or *footer will be
 * initially set to NULL.
 *
 * The application can detect that Header Metadata Block has been completely
 * parsed when the decoder procudes some output the first time. If *header
 * is still NULL, there was no Extra field in the Header Metadata Block (or
 * the whole Header Metadata Block wasn't present at all).
 *
 * The application can detect that Footer Metadata Block has been parsed
 * completely when lzma_code() returns LZMA_STREAM_END. If *footer is still
 * NULL, there was no Extra field in the Footer Metadata Block.
 *
 * \note        If you use lzma_memory_limiter, the Extra Records will be
 *              allocated with it, and thus remain in the lzma_memory_limiter
 *              even after they get exported to the application via *header
 *              and *footer pointers.
 */
extern lzma_ret lzma_stream_decoder(lzma_stream *strm,
		lzma_extra **header, lzma_extra **footer);