1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pub use self::decode::Decoder;
pub use self::encode::EncodeOptions;
pub use self::encode::Encoder;
pub use self::encode::DEFAULT_BLOCK_SIZE;
mod decode;
mod encode;
pub(crate) mod symbol;
#[derive(Debug, Clone, Copy)]
enum BlockType {
Raw = 0b00,
Fixed = 0b01,
Dynamic = 0b10,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::lz77;
use std::io::{Read, Write};
#[test]
fn encode_and_decode_works() {
let plain = (0..lz77::MAX_DISTANCE as u32 * 32)
.map(|i| i as u8)
.collect::<Vec<_>>();
let buffer = Vec::new();
let mut encoder = Encoder::new(buffer);
encoder.write_all(&plain[..]).expect("encode");
let encoded = encoder.finish().into_result().unwrap();
let mut buffer = Vec::new();
let mut decoder = Decoder::new(&encoded[..]);
decoder.read_to_end(&mut buffer).expect("decode");
assert_eq!(buffer, plain);
}
}