]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma/stream_flags.h
Imported to git.
[icculus/xz.git] / src / liblzma / api / lzma / stream_flags.h
1 /**
2  * \file        lzma/stream_flags.h
3  * \brief       .lzma Stream Header and Stream tail encoder and decoder
4  *
5  * \author      Copyright (C) 1999-2006 Igor Pavlov
6  * \author      Copyright (C) 2007 Lasse Collin
7  *
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.
12  *
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.
17  */
18
19 #ifndef LZMA_H_INTERNAL
20 #       error Never include this file directly. Use <lzma.h> instead.
21 #endif
22
23
24 /**
25  * \brief       Size of Stream Header
26  *
27  * Magic Bytes (6) + Stream Flags (1) + CRC32 (4)
28  */
29 #define LZMA_STREAM_HEADER_SIZE (6 + 1 + 4)
30
31
32 /**
33  * \brief       Size of Stream tail
34  *
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)
38  */
39 #define LZMA_STREAM_TAIL_SIZE (1 + 2)
40
41
42 /**
43  * Options for encoding and decoding Stream Header and Stream tail
44  */
45 typedef struct {
46         /**
47          * Type of the Check calculated from uncompressed data
48          */
49         lzma_check_type check;
50
51         /**
52          * True if Block Headers have the CRC32 field. Note that the CRC32
53          * field is always present in the Stream Header.
54          */
55         lzma_bool has_crc32;
56
57         /**
58          * True if the Stream is a Multi-Block Stream.
59          */
60         lzma_bool is_multi;
61
62 } lzma_stream_flags;
63
64
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)
69
70
71 /**
72  * \brief       Encodes Stream Header
73  *
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().
76  *
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.
82  *
83  * \return      - LZMA_OK: Encoding was successful.
84  *              - LZMA_PROG_ERROR: Invalid options.
85  *              - LZMA_BUF_ERROR: Not enough output buffer space.
86  */
87 extern lzma_ret lzma_stream_header_encode(
88                 uint8_t *out, const lzma_stream_flags *options);
89
90
91 /**
92  * \brief       Encodes Stream tail
93  *
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.
102  *
103  * \return      - LZMA_OK: Success; *header and *header_size set.
104  *              - LZMA_PROG_ERROR: *options is invalid.
105  *              - LZMA_MEM_ERROR: Cannot allocate memory.
106  */
107 extern lzma_ret lzma_stream_tail_encode(
108                 uint8_t *out, const lzma_stream_flags *options);
109
110
111 /**
112  * \brief       Initializes Stream Header decoder
113  *
114  * \param       strm        Pointer to lzma_stream used to pass input data
115  * \param       options     Target structure for parsed results
116  *
117  * \return      - LZMA_OK: Successfully initialized
118  *              - LZMA_MEM_ERROR: Cannot allocate memory
119  *
120  * The actual decoding is done with lzma_code() and freed with lzma_end().
121  */
122 extern lzma_ret lzma_stream_header_decoder(
123                 lzma_stream *strm, lzma_stream_flags *options);
124
125
126 /**
127  * \brief       Initializes Stream tail decoder
128  *
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.
135  *
136  * \return      - LZMA_OK: Successfully initialized
137  *              - LZMA_MEM_ERROR: Cannot allocate memory
138  *
139  * The actual decoding is done with lzma_code() and freed with lzma_end().
140  */
141 extern lzma_ret lzma_stream_tail_decoder(
142                 lzma_stream *strm, lzma_stream_flags *options);