Debian Codegraph @

third_party/rust/zlib-rs/src/deflate/algorithm/huff.rs

raw
1 #![forbid(unsafe_code)]
2
3 use crate::{
4 deflate::{fill_window, BlockState, DeflateStream},
5 flush_block, DeflateFlush,
6 };
7
8 pub fn deflate_huff(stream: &mut DeflateStream, flush: DeflateFlush) -> BlockState {
9 loop {
10 /* Make sure that we have a literal to write. */
11 if stream.state.lookahead == 0 {
12 fill_window(stream);
13
14 if stream.state.lookahead == 0 {
15 match flush {
16 DeflateFlush::NoFlush => return BlockState::NeedMore,
17 _ => break, /* flush the current block */
18 }
19 }
20 }
21
22 /* Output a literal byte */
23 let state = &mut stream.state;
24 let lc = state.window.filled()[state.strstart];
25 let bflush = state.tally_lit(lc);
26 state.lookahead -= 1;
27 state.strstart += 1;
28 if bflush {
29 flush_block!(stream, false);
30 }
31 }
32
33 stream.state.insert = 0;
34
35 if flush == DeflateFlush::Finish {
36 flush_block!(stream, true);
37 return BlockState::FinishDone;
38 }
39
40 if !stream.state.sym_buf.is_empty() {
41 flush_block!(stream, false);
42 }
43
44 BlockState::BlockDone
45 }