1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file stream_flags_encoder.c
4 /// \brief Encodes Stream Header and Footer for .lzma files
6 // 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.
18 ///////////////////////////////////////////////////////////////////////////////
20 #include "stream_common.h"
24 stream_flags_encode(uint8_t *flags_byte, const lzma_stream_flags *options)
27 if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX)
30 *flags_byte = options->check;
32 // Usage of CRC32 in Block Headers
33 if (options->has_crc32)
36 // Single- or Multi-Block
37 if (options->is_multi)
44 extern LZMA_API lzma_ret
45 lzma_stream_header_encode(uint8_t *out, const lzma_stream_flags *options)
48 memcpy(out, lzma_header_magic, sizeof(lzma_header_magic));
51 if (stream_flags_encode(out + sizeof(lzma_header_magic), options))
52 return LZMA_PROG_ERROR;;
54 // CRC32 of the Stream Header
55 const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic), 1, 0);
57 for (size_t i = 0; i < 4; ++i)
58 out[sizeof(lzma_header_magic) + 1 + i] = crc >> (i * 8);
64 extern LZMA_API lzma_ret
65 lzma_stream_tail_encode(uint8_t *out, const lzma_stream_flags *options)
68 if (stream_flags_encode(out, options))
69 return LZMA_PROG_ERROR;
72 memcpy(out + 1, lzma_footer_magic, sizeof(lzma_footer_magic));