1use std::io;
23use super::{Decoder, Encoder};
45/// Decompress from the given source as if using a `Decoder`.
6///
7/// The input data must be in the zstd frame format.
8pub fn decode_all<R: io::Read>(source: R) -> io::Result<Vec<u8>> {
9let mut result = Vec::new();
10 copy_decode(source, &mut result)?;
11Ok(result)
12}
1314/// Decompress from the given source as if using a `Decoder`.
15///
16/// Decompressed data will be appended to `destination`.
17pub fn copy_decode<R, W>(source: R, mut destination: W) -> io::Result<()>
18where
19R: io::Read,
20 W: io::Write,
21{
22let mut decoder = Decoder::new(source)?;
23 io::copy(&mut decoder, &mut destination)?;
24Ok(())
25}
2627/// Compress all data from the given source as if using an `Encoder`.
28///
29/// Result will be in the zstd frame format.
30///
31/// A level of `0` uses zstd's default (currently `3`).
32pub fn encode_all<R: io::Read>(source: R, level: i32) -> io::Result<Vec<u8>> {
33let mut result = Vec::<u8>::new();
34 copy_encode(source, &mut result, level)?;
35Ok(result)
36}
3738/// Compress all data from the given source as if using an `Encoder`.
39///
40/// Compressed data will be appended to `destination`.
41///
42/// A level of `0` uses zstd's default (currently `3`).
43pub fn copy_encode<R, W>(
44mut source: R,
45 destination: W,
46 level: i32,
47) -> io::Result<()>
48where
49R: io::Read,
50 W: io::Write,
51{
52let mut encoder = Encoder::new(destination, level)?;
53 io::copy(&mut source, &mut encoder)?;
54 encoder.finish()?;
55Ok(())
56}
5758#[cfg(tests)]
59mod tests {}