Skip to content

Commit

Permalink
Simplify and streaming estimators (#22)
Browse files Browse the repository at this point in the history
* cleaup complevel estimator

* cleanup more

* work
  • Loading branch information
mcroomp authored Feb 6, 2025
1 parent 29f2696 commit cabd078
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 218 deletions.
29 changes: 29 additions & 0 deletions src/deflate/deflate_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ pub enum DeflateTokenBlock {
},
}

impl DeflateTokenBlock {
pub fn append_to_plaintext(&self, dest: &mut Vec<u8>) {
match self {
DeflateTokenBlock::Huffman { tokens, .. } => {
for &token in tokens.iter() {
match token {
DeflateToken::Literal(l) => {
dest.push(l);
}
DeflateToken::Reference(r) => {
assert!(dest.len() >= r.dist() as usize);

let mut index = dest.len() - r.dist() as usize;
for _i in 0..r.len() {
let l = dest[index];
dest.push(l);
index += 1;
}
}
}
}
}
DeflateTokenBlock::Stored { uncompressed, .. } => {
dest.extend_from_slice(&uncompressed);
}
}
}
}

/// Used to track the frequence of tokens in the DEFLATE stream
/// which are later used to build the huffman encoding.
#[derive(Debug)]
Expand Down
Loading

0 comments on commit cabd078

Please sign in to comment.