xref: /freebsd/contrib/xz/src/liblzma/common/block_encoder.h (revision 532000256b898d5d3b0067ffa328715d18f4776d)
181ad8388SMartin Matuska ///////////////////////////////////////////////////////////////////////////////
281ad8388SMartin Matuska //
381ad8388SMartin Matuska /// \file       block_encoder.h
481ad8388SMartin Matuska /// \brief      Encodes .xz Blocks
581ad8388SMartin Matuska //
681ad8388SMartin Matuska //  Author:     Lasse Collin
781ad8388SMartin Matuska //
881ad8388SMartin Matuska //  This file has been put into the public domain.
981ad8388SMartin Matuska //  You can do whatever you want with this file.
1081ad8388SMartin Matuska //
1181ad8388SMartin Matuska ///////////////////////////////////////////////////////////////////////////////
1281ad8388SMartin Matuska 
1381ad8388SMartin Matuska #ifndef LZMA_BLOCK_ENCODER_H
1481ad8388SMartin Matuska #define LZMA_BLOCK_ENCODER_H
1581ad8388SMartin Matuska 
1681ad8388SMartin Matuska #include "common.h"
1781ad8388SMartin Matuska 
1881ad8388SMartin Matuska 
1981ad8388SMartin Matuska /// \brief      Biggest Compressed Size value that the Block encoder supports
2081ad8388SMartin Matuska ///
2181ad8388SMartin Matuska /// The maximum size of a single Block is limited by the maximum size of
2281ad8388SMartin Matuska /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3).
2381ad8388SMartin Matuska /// While the size is really big and no one should hit it in practice, we
2481ad8388SMartin Matuska /// take it into account in some places anyway to catch some errors e.g. if
2581ad8388SMartin Matuska /// application passes insanely big value to some function.
2681ad8388SMartin Matuska ///
2781ad8388SMartin Matuska /// We could take into account the headers etc. to determine the exact
2881ad8388SMartin Matuska /// maximum size of the Compressed Data field, but the complexity would give
2981ad8388SMartin Matuska /// us nothing useful. Instead, limit the size of Compressed Data so that
3081ad8388SMartin Matuska /// even with biggest possible Block Header and Check fields the total
3181ad8388SMartin Matuska /// encoded size of the Block stays as a valid VLI. This doesn't guarantee
3281ad8388SMartin Matuska /// that the size of the Stream doesn't grow too big, but that problem is
3381ad8388SMartin Matuska /// taken care outside the Block handling code.
3481ad8388SMartin Matuska ///
3581ad8388SMartin Matuska /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of
3681ad8388SMartin Matuska /// the Compressed Data field, it will still stay in the proper limit.
3781ad8388SMartin Matuska ///
3881ad8388SMartin Matuska /// This constant is in this file because it is needed in both
3981ad8388SMartin Matuska /// block_encoder.c and block_buffer_encoder.c.
4081ad8388SMartin Matuska #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \
4181ad8388SMartin Matuska 		- LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3))
4281ad8388SMartin Matuska 
4381ad8388SMartin Matuska 
4481ad8388SMartin Matuska extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
45*53200025SRui Paulo 		const lzma_allocator *allocator, lzma_block *block);
4681ad8388SMartin Matuska 
4781ad8388SMartin Matuska #endif
48