xref: /dflybsd-src/contrib/xz/src/liblzma/common/block_encoder.h (revision 4381ed9d7ee193d719c4e4a94a9d267d177981c1)
12940b44dSPeter Avalos ///////////////////////////////////////////////////////////////////////////////
22940b44dSPeter Avalos //
32940b44dSPeter Avalos /// \file       block_encoder.h
42940b44dSPeter Avalos /// \brief      Encodes .xz Blocks
52940b44dSPeter Avalos //
62940b44dSPeter Avalos //  Author:     Lasse Collin
72940b44dSPeter Avalos //
82940b44dSPeter Avalos //  This file has been put into the public domain.
92940b44dSPeter Avalos //  You can do whatever you want with this file.
102940b44dSPeter Avalos //
112940b44dSPeter Avalos ///////////////////////////////////////////////////////////////////////////////
122940b44dSPeter Avalos 
132940b44dSPeter Avalos #ifndef LZMA_BLOCK_ENCODER_H
142940b44dSPeter Avalos #define LZMA_BLOCK_ENCODER_H
152940b44dSPeter Avalos 
162940b44dSPeter Avalos #include "common.h"
172940b44dSPeter Avalos 
182940b44dSPeter Avalos 
192940b44dSPeter Avalos /// \brief      Biggest Compressed Size value that the Block encoder supports
202940b44dSPeter Avalos ///
212940b44dSPeter Avalos /// The maximum size of a single Block is limited by the maximum size of
222940b44dSPeter Avalos /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3).
232940b44dSPeter Avalos /// While the size is really big and no one should hit it in practice, we
242940b44dSPeter Avalos /// take it into account in some places anyway to catch some errors e.g. if
252940b44dSPeter Avalos /// application passes insanely big value to some function.
262940b44dSPeter Avalos ///
272940b44dSPeter Avalos /// We could take into account the headers etc. to determine the exact
282940b44dSPeter Avalos /// maximum size of the Compressed Data field, but the complexity would give
292940b44dSPeter Avalos /// us nothing useful. Instead, limit the size of Compressed Data so that
302940b44dSPeter Avalos /// even with biggest possible Block Header and Check fields the total
312940b44dSPeter Avalos /// encoded size of the Block stays as a valid VLI. This doesn't guarantee
322940b44dSPeter Avalos /// that the size of the Stream doesn't grow too big, but that problem is
332940b44dSPeter Avalos /// taken care outside the Block handling code.
342940b44dSPeter Avalos ///
352940b44dSPeter Avalos /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of
362940b44dSPeter Avalos /// the Compressed Data field, it will still stay in the proper limit.
372940b44dSPeter Avalos ///
382940b44dSPeter Avalos /// This constant is in this file because it is needed in both
392940b44dSPeter Avalos /// block_encoder.c and block_buffer_encoder.c.
402940b44dSPeter Avalos #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \
412940b44dSPeter Avalos 		- LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3))
422940b44dSPeter Avalos 
432940b44dSPeter Avalos 
442940b44dSPeter Avalos extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
45*15ab8c86SJohn Marino 		const lzma_allocator *allocator, lzma_block *block);
462940b44dSPeter Avalos 
472940b44dSPeter Avalos #endif
48