1use std::io;
2
3use super::{Decoder, Encoder};
4
5pub fn decode_all<R: io::Read>(source: R) -> io::Result<Vec<u8>> {
9 let mut result = Vec::new();
10 copy_decode(source, &mut result)?;
11 Ok(result)
12}
13
14pub fn copy_decode<R, W>(source: R, mut destination: W) -> io::Result<()>
18where
19 R: io::Read,
20 W: io::Write,
21{
22 let mut decoder = Decoder::new(source)?;
23 io::copy(&mut decoder, &mut destination)?;
24 Ok(())
25}
26
27pub fn encode_all<R: io::Read>(source: R, level: i32) -> io::Result<Vec<u8>> {
33 let mut result = Vec::<u8>::new();
34 copy_encode(source, &mut result, level)?;
35 Ok(result)
36}
37
38pub fn copy_encode<R, W>(
44 mut source: R,
45 destination: W,
46 level: i32,
47) -> io::Result<()>
48where
49 R: io::Read,
50 W: io::Write,
51{
52 let mut encoder = Encoder::new(destination, level)?;
53 io::copy(&mut source, &mut encoder)?;
54 encoder.finish()?;
55 Ok(())
56}
57
58#[cfg(tests)]
59mod tests {}