xref: /freebsd/contrib/xz/src/liblzma/common/block_encoder.h (revision 81ad83880dcc267b198c781929dd9a009f98c5f7)
1*81ad8388SMartin Matuska ///////////////////////////////////////////////////////////////////////////////
2*81ad8388SMartin Matuska //
3*81ad8388SMartin Matuska /// \file       block_encoder.h
4*81ad8388SMartin Matuska /// \brief      Encodes .xz Blocks
5*81ad8388SMartin Matuska //
6*81ad8388SMartin Matuska //  Author:     Lasse Collin
7*81ad8388SMartin Matuska //
8*81ad8388SMartin Matuska //  This file has been put into the public domain.
9*81ad8388SMartin Matuska //  You can do whatever you want with this file.
10*81ad8388SMartin Matuska //
11*81ad8388SMartin Matuska ///////////////////////////////////////////////////////////////////////////////
12*81ad8388SMartin Matuska 
13*81ad8388SMartin Matuska #ifndef LZMA_BLOCK_ENCODER_H
14*81ad8388SMartin Matuska #define LZMA_BLOCK_ENCODER_H
15*81ad8388SMartin Matuska 
16*81ad8388SMartin Matuska #include "common.h"
17*81ad8388SMartin Matuska 
18*81ad8388SMartin Matuska 
19*81ad8388SMartin Matuska /// \brief      Biggest Compressed Size value that the Block encoder supports
20*81ad8388SMartin Matuska ///
21*81ad8388SMartin Matuska /// The maximum size of a single Block is limited by the maximum size of
22*81ad8388SMartin Matuska /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3).
23*81ad8388SMartin Matuska /// While the size is really big and no one should hit it in practice, we
24*81ad8388SMartin Matuska /// take it into account in some places anyway to catch some errors e.g. if
25*81ad8388SMartin Matuska /// application passes insanely big value to some function.
26*81ad8388SMartin Matuska ///
27*81ad8388SMartin Matuska /// We could take into account the headers etc. to determine the exact
28*81ad8388SMartin Matuska /// maximum size of the Compressed Data field, but the complexity would give
29*81ad8388SMartin Matuska /// us nothing useful. Instead, limit the size of Compressed Data so that
30*81ad8388SMartin Matuska /// even with biggest possible Block Header and Check fields the total
31*81ad8388SMartin Matuska /// encoded size of the Block stays as a valid VLI. This doesn't guarantee
32*81ad8388SMartin Matuska /// that the size of the Stream doesn't grow too big, but that problem is
33*81ad8388SMartin Matuska /// taken care outside the Block handling code.
34*81ad8388SMartin Matuska ///
35*81ad8388SMartin Matuska /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of
36*81ad8388SMartin Matuska /// the Compressed Data field, it will still stay in the proper limit.
37*81ad8388SMartin Matuska ///
38*81ad8388SMartin Matuska /// This constant is in this file because it is needed in both
39*81ad8388SMartin Matuska /// block_encoder.c and block_buffer_encoder.c.
40*81ad8388SMartin Matuska #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \
41*81ad8388SMartin Matuska 		- LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3))
42*81ad8388SMartin Matuska 
43*81ad8388SMartin Matuska 
44*81ad8388SMartin Matuska extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
45*81ad8388SMartin Matuska 		lzma_allocator *allocator, lzma_block *block);
46*81ad8388SMartin Matuska 
47*81ad8388SMartin Matuska #endif
48