Debian Codegraph @

debian/rust-vendor/zlib-rs/src/deflate/algorithm/huff.rs

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