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
62
63
64
65
66
67
68
69
70
71
72
73
74
#![deny(missing_docs)]
extern crate libc;
mod ll;
mod stream;
pub mod block;
pub mod dict;
pub use stream::encoder::Encoder;
pub use stream::decoder::Decoder;
use std::io;
pub fn decode_all(data: &[u8]) -> io::Result<Vec<u8>> {
let mut result = Vec::new();
let mut decoder = try!(Decoder::new(data));
try!(io::copy(&mut decoder, &mut result));
Ok(result)
}
pub fn encode_all(data: &[u8], level: i32) -> io::Result<Vec<u8>> {
let result = Vec::<u8>::new();
let mut encoder = try!(Encoder::new(result, level));
let mut input = data;
try!(io::copy(&mut input, &mut encoder));
encoder.finish()
}
#[test]
fn test_cycle() {
let text = "This is a sample text. It is not meant to be interesting or \
anything. Just text, nothing more. Don't expect too much \
from it.";
let compressed = encode_all(text.as_bytes(), 1).unwrap();
let decompressed = String::from_utf8(decode_all(&compressed).unwrap())
.unwrap();
assert_eq!(text, &decompressed);
}