mirror of
https://github.com/boostorg/beast.git
synced 2025-07-31 13:27:33 +02:00
committed by
Mohammad Nejati
parent
5f088b72ca
commit
dc8798c917
@ -79,7 +79,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
deflate_stream()
|
deflate_stream()
|
||||||
{
|
{
|
||||||
reset(6, 15, DEF_MEM_LEVEL, Strategy::normal);
|
reset(6, 15, def_mem_level, Strategy::normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reset the stream and compression settings.
|
/** Reset the stream and compression settings.
|
||||||
|
@ -90,27 +90,27 @@ protected:
|
|||||||
BOOST_STATIC_ASSERT(minMatch == 3);
|
BOOST_STATIC_ASSERT(minMatch == 3);
|
||||||
|
|
||||||
// end of block literal code
|
// end of block literal code
|
||||||
static std::uint16_t constexpr END_BLOCK = 256;
|
static std::uint16_t constexpr end_block = 256;
|
||||||
|
|
||||||
// repeat previous bit length 3-6 times (2 bits of repeat count)
|
// repeat previous bit length 3-6 times (2 bits of repeat count)
|
||||||
static std::uint8_t constexpr REP_3_6 = 16;
|
static std::uint8_t constexpr rep_3_6 = 16;
|
||||||
|
|
||||||
// repeat a zero length 3-10 times (3 bits of repeat count)
|
// repeat a zero length 3-10 times (3 bits of repeat count)
|
||||||
static std::uint8_t constexpr REPZ_3_10 = 17;
|
static std::uint8_t constexpr repz_3_10 = 17;
|
||||||
|
|
||||||
// repeat a zero length 11-138 times (7 bits of repeat count)
|
// repeat a zero length 11-138 times (7 bits of repeat count)
|
||||||
static std::uint8_t constexpr REPZ_11_138 = 18;
|
static std::uint8_t constexpr repz_11_138 = 18;
|
||||||
|
|
||||||
// The three kinds of block type
|
// The three kinds of block type
|
||||||
static std::uint8_t constexpr STORED_BLOCK = 0;
|
static std::uint8_t constexpr stored_block = 0;
|
||||||
static std::uint8_t constexpr STATIC_TREES = 1;
|
static std::uint8_t constexpr static_trees = 1;
|
||||||
static std::uint8_t constexpr DYN_TREES = 2;
|
static std::uint8_t constexpr dyn_trees = 2;
|
||||||
|
|
||||||
// Maximum value for memLevel in deflateInit2
|
// Maximum value for memLevel in deflateInit2
|
||||||
static std::uint8_t constexpr max_mem_level = 9;
|
static std::uint8_t constexpr max_mem_level = 9;
|
||||||
|
|
||||||
// Default memLevel
|
// Default memLevel
|
||||||
static std::uint8_t constexpr DEF_MEM_LEVEL = max_mem_level;
|
static std::uint8_t constexpr def_mem_level = max_mem_level;
|
||||||
|
|
||||||
/* Note: the deflate() code requires max_lazy >= minMatch and max_chain >= 4
|
/* Note: the deflate() code requires max_lazy >= minMatch and max_chain >= 4
|
||||||
For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||||
@ -118,7 +118,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// maximum heap size
|
// maximum heap size
|
||||||
static std::uint16_t constexpr HEAP_SIZE = 2 * lCodes + 1;
|
static std::uint16_t constexpr heap_size = 2 * lCodes + 1;
|
||||||
|
|
||||||
// size of bit buffer in bi_buf
|
// size of bit buffer in bi_buf
|
||||||
static std::uint8_t constexpr Buf_size = 16;
|
static std::uint8_t constexpr Buf_size = 16;
|
||||||
@ -229,12 +229,12 @@ protected:
|
|||||||
// VFALCO This might not be needed, e.g. for zip/gzip
|
// VFALCO This might not be needed, e.g. for zip/gzip
|
||||||
enum StreamStatus
|
enum StreamStatus
|
||||||
{
|
{
|
||||||
EXTRA_STATE = 69,
|
extra_state = 69,
|
||||||
NAME_STATE = 73,
|
name_state = 73,
|
||||||
COMMENT_STATE = 91,
|
comment_state = 91,
|
||||||
HCRC_STATE = 103,
|
hcrc_state = 103,
|
||||||
BUSY_STATE = 113,
|
busy_state = 113,
|
||||||
FINISH_STATE = 666
|
finish_state = 666
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A std::uint16_t is an index in the character window. We use short instead of int to
|
/* A std::uint16_t is an index in the character window. We use short instead of int to
|
||||||
@ -343,7 +343,7 @@ protected:
|
|||||||
int nice_match_; // Stop searching when current match exceeds this
|
int nice_match_; // Stop searching when current match exceeds this
|
||||||
|
|
||||||
ct_data dyn_ltree_[
|
ct_data dyn_ltree_[
|
||||||
HEAP_SIZE]; // literal and length tree
|
heap_size]; // literal and length tree
|
||||||
ct_data dyn_dtree_[
|
ct_data dyn_dtree_[
|
||||||
2*dCodes+1]; // distance tree
|
2*dCodes+1]; // distance tree
|
||||||
ct_data bl_tree_[
|
ct_data bl_tree_[
|
||||||
|
@ -364,7 +364,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
|
|||||||
BOOST_THROW_EXCEPTION(std::invalid_argument{"invalid input"});
|
BOOST_THROW_EXCEPTION(std::invalid_argument{"invalid input"});
|
||||||
|
|
||||||
if(zs.next_out == nullptr ||
|
if(zs.next_out == nullptr ||
|
||||||
(status_ == FINISH_STATE && flush != Flush::finish))
|
(status_ == finish_state && flush != Flush::finish))
|
||||||
{
|
{
|
||||||
BOOST_BEAST_ASSIGN_EC(ec, error::stream_error);
|
BOOST_BEAST_ASSIGN_EC(ec, error::stream_error);
|
||||||
return;
|
return;
|
||||||
@ -411,7 +411,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// User must not provide more input after the first FINISH:
|
// User must not provide more input after the first FINISH:
|
||||||
if(status_ == FINISH_STATE && zs.avail_in != 0)
|
if(status_ == finish_state && zs.avail_in != 0)
|
||||||
{
|
{
|
||||||
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
|
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
|
||||||
return;
|
return;
|
||||||
@ -420,7 +420,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
|
|||||||
/* Start a new block or continue the current one.
|
/* Start a new block or continue the current one.
|
||||||
*/
|
*/
|
||||||
if(zs.avail_in != 0 || lookahead_ != 0 ||
|
if(zs.avail_in != 0 || lookahead_ != 0 ||
|
||||||
(flush != Flush::none && status_ != FINISH_STATE))
|
(flush != Flush::none && status_ != finish_state))
|
||||||
{
|
{
|
||||||
block_state bstate;
|
block_state bstate;
|
||||||
|
|
||||||
@ -441,7 +441,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
|
|||||||
|
|
||||||
if(bstate == finish_started || bstate == finish_done)
|
if(bstate == finish_started || bstate == finish_done)
|
||||||
{
|
{
|
||||||
status_ = FINISH_STATE;
|
status_ = finish_state;
|
||||||
}
|
}
|
||||||
if(bstate == need_more || bstate == finish_started)
|
if(bstate == need_more || bstate == finish_started)
|
||||||
{
|
{
|
||||||
@ -681,7 +681,7 @@ init()
|
|||||||
pending_ = 0;
|
pending_ = 0;
|
||||||
pending_out_ = pending_buf_;
|
pending_out_ = pending_buf_;
|
||||||
|
|
||||||
status_ = BUSY_STATE;
|
status_ = busy_state;
|
||||||
last_flush_ = Flush::none;
|
last_flush_ = Flush::none;
|
||||||
|
|
||||||
tr_init();
|
tr_init();
|
||||||
@ -729,7 +729,7 @@ init_block()
|
|||||||
dyn_dtree_[n].fc = 0;
|
dyn_dtree_[n].fc = 0;
|
||||||
for(int n = 0; n < blCodes; n++)
|
for(int n = 0; n < blCodes; n++)
|
||||||
bl_tree_[n].fc = 0;
|
bl_tree_[n].fc = 0;
|
||||||
dyn_ltree_[END_BLOCK].fc = 1;
|
dyn_ltree_[end_block].fc = 1;
|
||||||
opt_len_ = 0L;
|
opt_len_ = 0L;
|
||||||
static_len_ = 0L;
|
static_len_ = 0L;
|
||||||
sym_next_ = 0;
|
sym_next_ = 0;
|
||||||
@ -815,7 +815,7 @@ gen_bitlen(tree_desc *desc)
|
|||||||
*/
|
*/
|
||||||
tree[heap_[heap_max_]].dl = 0; // root of the heap
|
tree[heap_[heap_max_]].dl = 0; // root of the heap
|
||||||
|
|
||||||
for(h = heap_max_+1; h < HEAP_SIZE; h++) {
|
for(h = heap_max_+1; h < heap_size; h++) {
|
||||||
n = heap_[h];
|
n = heap_[h];
|
||||||
bits = tree[tree[n].dl].dl + 1;
|
bits = tree[tree[n].dl].dl + 1;
|
||||||
if(bits > max_length) bits = max_length, overflow++;
|
if(bits > max_length) bits = max_length, overflow++;
|
||||||
@ -899,7 +899,7 @@ build_tree(tree_desc *desc)
|
|||||||
* heap[0] is not used.
|
* heap[0] is not used.
|
||||||
*/
|
*/
|
||||||
heap_len_ = 0;
|
heap_len_ = 0;
|
||||||
heap_max_ = HEAP_SIZE;
|
heap_max_ = heap_size;
|
||||||
|
|
||||||
for(n = 0; n < elems; n++)
|
for(n = 0; n < elems; n++)
|
||||||
{
|
{
|
||||||
@ -1010,15 +1010,15 @@ scan_tree(
|
|||||||
else if(curlen != 0)
|
else if(curlen != 0)
|
||||||
{
|
{
|
||||||
if(curlen != prevlen) bl_tree_[curlen].fc++;
|
if(curlen != prevlen) bl_tree_[curlen].fc++;
|
||||||
bl_tree_[REP_3_6].fc++;
|
bl_tree_[rep_3_6].fc++;
|
||||||
}
|
}
|
||||||
else if(count <= 10)
|
else if(count <= 10)
|
||||||
{
|
{
|
||||||
bl_tree_[REPZ_3_10].fc++;
|
bl_tree_[repz_3_10].fc++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bl_tree_[REPZ_11_138].fc++;
|
bl_tree_[repz_11_138].fc++;
|
||||||
}
|
}
|
||||||
count = 0;
|
count = 0;
|
||||||
prevlen = curlen;
|
prevlen = curlen;
|
||||||
@ -1088,17 +1088,17 @@ send_tree(
|
|||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
BOOST_ASSERT(count >= 3 && count <= 6);
|
BOOST_ASSERT(count >= 3 && count <= 6);
|
||||||
send_code(REP_3_6, bl_tree_);
|
send_code(rep_3_6, bl_tree_);
|
||||||
send_bits(count-3, 2);
|
send_bits(count-3, 2);
|
||||||
}
|
}
|
||||||
else if(count <= 10)
|
else if(count <= 10)
|
||||||
{
|
{
|
||||||
send_code(REPZ_3_10, bl_tree_);
|
send_code(repz_3_10, bl_tree_);
|
||||||
send_bits(count-3, 3);
|
send_bits(count-3, 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
send_code(REPZ_11_138, bl_tree_);
|
send_code(repz_11_138, bl_tree_);
|
||||||
send_bits(count-11, 7);
|
send_bits(count-11, 7);
|
||||||
}
|
}
|
||||||
count = 0;
|
count = 0;
|
||||||
@ -1234,7 +1234,7 @@ compress_block(
|
|||||||
while(sx < sym_next_);
|
while(sx < sym_next_);
|
||||||
}
|
}
|
||||||
|
|
||||||
send_code(END_BLOCK, ltree);
|
send_code(end_block, ltree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the data type is TEXT or BINARY, using the following algorithm:
|
/* Check if the data type is TEXT or BINARY, using the following algorithm:
|
||||||
@ -1366,8 +1366,8 @@ void
|
|||||||
deflate_stream::
|
deflate_stream::
|
||||||
tr_align()
|
tr_align()
|
||||||
{
|
{
|
||||||
send_bits(STATIC_TREES<<1, 3);
|
send_bits(static_trees<<1, 3);
|
||||||
send_code(END_BLOCK, lut_.ltree);
|
send_code(end_block, lut_.ltree);
|
||||||
bi_flush();
|
bi_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1389,7 +1389,7 @@ tr_stored_block(
|
|||||||
std::uint32_t stored_len, // length of input block
|
std::uint32_t stored_len, // length of input block
|
||||||
int last) // one if this is the last block for a file
|
int last) // one if this is the last block for a file
|
||||||
{
|
{
|
||||||
send_bits((STORED_BLOCK<<1)+last, 3); // send block type
|
send_bits((stored_block<<1)+last, 3); // send block type
|
||||||
copy_block(buf, (unsigned)stored_len, 1); // with header
|
copy_block(buf, (unsigned)stored_len, 1); // with header
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1497,12 +1497,12 @@ tr_flush_block(
|
|||||||
else if(strategy_ == Strategy::fixed || static_lenb == opt_lenb)
|
else if(strategy_ == Strategy::fixed || static_lenb == opt_lenb)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
send_bits((STATIC_TREES<<1)+last, 3);
|
send_bits((static_trees<<1)+last, 3);
|
||||||
compress_block(lut_.ltree, lut_.dtree);
|
compress_block(lut_.ltree, lut_.dtree);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
send_bits((DYN_TREES<<1)+last, 3);
|
send_bits((dyn_trees<<1)+last, 3);
|
||||||
send_all_trees(l_desc_.max_code+1, d_desc_.max_code+1,
|
send_all_trees(l_desc_.max_code+1, d_desc_.max_code+1,
|
||||||
max_blindex+1);
|
max_blindex+1);
|
||||||
compress_block((const ct_data *)dyn_ltree_,
|
compress_block((const ct_data *)dyn_ltree_,
|
||||||
|
Reference in New Issue
Block a user