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
use std::io;
use super::{Decoder, Encoder};
pub fn decode_all<R: io::Read>(source: R) -> io::Result<Vec<u8>> {
let mut result = Vec::new();
copy_decode(source, &mut result)?;
Ok(result)
}
pub fn copy_decode<R, W>(source: R, mut destination: W) -> io::Result<()>
where
R: io::Read,
W: io::Write,
{
let mut decoder = Decoder::new(source)?;
io::copy(&mut decoder, &mut destination)?;
Ok(())
}
pub fn encode_all<R: io::Read>(source: R, level: i32) -> io::Result<Vec<u8>> {
let mut result = Vec::<u8>::new();
copy_encode(source, &mut result, level)?;
Ok(result)
}
pub fn copy_encode<R, W>(
mut source: R,
destination: W,
level: i32,
) -> io::Result<()>
where
R: io::Read,
W: io::Write,
{
let mut encoder = Encoder::new(destination, level)?;
io::copy(&mut source, &mut encoder)?;
encoder.finish()?;
Ok(())
}
#[cfg(tests)]
mod tests {}