]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma/stream_flags.h
Update the code to mostly match the new simpler file format
[icculus/xz.git] / src / liblzma / api / lzma / stream_flags.h
1 /**
2  * \file        lzma/stream_flags.h
3  * \brief       .lzma Stream Header and Stream Footer 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 and Stream Footer
26  *
27  * Stream Header and Stream Footer have the same size and they are not
28  * going to change even if a newer version of the .lzma file format is
29  * developed in future.
30  */
31 #define LZMA_STREAM_HEADER_SIZE 12
32
33
34 /**
35  * Options for encoding and decoding Stream Header and Stream Footer
36  */
37 typedef struct {
38         /**
39          * Backward Size must be a multiple of four bytes. In this Stream
40          * format version Backward Size is the size of the Index field.
41          */
42         lzma_vli backward_size;
43 #       define LZMA_BACKWARD_SIZE_MIN 4
44 #       define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
45
46         /**
47          * Type of the Check calculated from uncompressed data
48          */
49         lzma_check_type check;
50
51 } lzma_stream_flags;
52
53
54 /**
55  * \brief       Encode Stream Header
56  *
57  * \param       out         Beginning of the output buffer of
58  *                          LZMA_STREAM_HEADER_SIZE bytes.
59  * \param       options     Stream Header options to be encoded.
60  *                          options->index_size is ignored and doesn't
61  *                          need to be initialized.
62  *
63  * \return      - LZMA_OK: Encoding was successful.
64  *              - LZMA_PROG_ERROR: Invalid options.
65  */
66 extern lzma_ret lzma_stream_header_encode(
67                 const lzma_stream_flags *options, uint8_t *out);
68
69
70 /**
71  * \brief       Encode Stream Footer
72  *
73  * \param       out         Beginning of the output buffer of
74  *                          LZMA_STREAM_HEADER_SIZE bytes.
75  * \param       options     Stream Footer options to be encoded.
76  *
77  * \return      - LZMA_OK: Encoding was successful.
78  *              - LZMA_PROG_ERROR: Invalid options.
79  */
80 extern lzma_ret lzma_stream_footer_encode(
81                 const lzma_stream_flags *options, uint8_t *out);
82
83
84 /**
85  * \brief       Decode Stream Header
86  *
87  * \param       options     Stream Header options to be encoded.
88  * \param       in          Beginning of the input buffer of
89  *                          LZMA_STREAM_HEADER_SIZE bytes.
90  *
91  * options->index_size is always set to LZMA_VLI_VALUE_UNKNOWN. This is to
92  * help comparing Stream Flags from Stream Header and Stream Footer with
93  * lzma_stream_flags_equal().
94  *
95  * \return      - LZMA_OK: Decoding was successful.
96  *              - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
97  *                buffer cannot be Stream Header.
98  *              - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
99  *                is corrupt.
100  *              - LZMA_HEADER_ERROR: Unsupported options are present
101  *                in the header.
102  */
103 extern lzma_ret lzma_stream_header_decode(
104                 lzma_stream_flags *options, const uint8_t *in);
105
106
107 /**
108  * \brief       Decode Stream Footer
109  *
110  * \param       options     Stream Header options to be encoded.
111  * \param       in          Beginning of the input buffer of
112  *                          LZMA_STREAM_HEADER_SIZE bytes.
113  *
114  * \return      - LZMA_OK: Decoding was successful.
115  *              - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
116  *                buffer cannot be Stream Footer.
117  *              - LZMA_DATA_ERROR: CRC32 doesn't match, thus the footer
118  *                is corrupt.
119  *              - LZMA_HEADER_ERROR: Unsupported options are present
120  *                in the footer.
121  */
122 extern lzma_ret lzma_stream_footer_decode(
123                 lzma_stream_flags *options, const uint8_t *in);
124
125
126 /**
127  * \brief       Compare two lzma_stream_flags structures
128  *
129  * index_size values are compared only if both are not LZMA_VLI_VALUE_UNKNOWN.
130  *
131  * \return      true if both structures are considered equal; false otherwise.
132  */
133 extern lzma_bool lzma_stream_flags_equal(
134                 const lzma_stream_flags *a, lzma_stream_flags *b);