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
75
76
77
78
79
80
81
82
mod compressor;
mod decompressor;
pub use self::compressor::Compressor;
pub use self::decompressor::Decompressor;
use std::io;
pub fn compress_to_buffer(
source: &[u8],
destination: &mut [u8],
level: i32,
) -> io::Result<usize> {
Compressor::new().compress_to_buffer(source, destination, level)
}
pub fn compress(data: &[u8], level: i32) -> io::Result<Vec<u8>> {
Compressor::new().compress(data, level)
}
pub fn decompress_to_buffer(
source: &[u8],
destination: &mut [u8],
) -> io::Result<usize> {
Decompressor::new().decompress_to_buffer(source, destination)
}
pub fn decompress(data: &[u8], capacity: usize) -> io::Result<Vec<u8>> {
Decompressor::new().decompress(data, capacity)
}
#[cfg(test)]
mod tests {
use super::{compress, decompress};
#[test]
fn test_direct() {
let text = "Pork belly art party wolf XOXO, neutra scenester ugh \
thundercats tattooed squid skateboard beard readymade \
kogi. VHS cardigan schlitz, meditation chartreuse kogi \
tilde church-key. Actually direct trade hammock, \
aesthetic VHS semiotics organic narwhal lo-fi heirloom \
flexitarian master cleanse polaroid man bun. Flannel \
helvetica mustache, bicycle rights small batch slow-carb \
neutra tilde williamsburg meh poutine humblebrag. Four \
dollar toast butcher actually franzen, gastropub \
mustache tofu cardigan. 90's fingerstache forage \
brooklyn meditation single-origin coffee tofu actually, \
ramps pabst farm-to-table art party kombucha artisan \
fanny pack. Flannel salvia ennui viral leggings selfies.";
crate::test_cycle_unwrap(
text.as_bytes(),
|data| compress(data, 1),
|data| decompress(data, text.len()),
);
}
}