compression_codecs/xz/
encoder.rs

1use crate::{EncodeV2, Xz2Encoder, Xz2FileFormat};
2use compression_core::{
3    util::{PartialBuffer, WriteBuffer},
4    Level,
5};
6use std::io::Result;
7
8/// Xz encoding stream
9#[derive(Debug)]
10pub struct XzEncoder {
11    inner: Xz2Encoder,
12}
13
14impl XzEncoder {
15    pub fn new(level: Level) -> Self {
16        Self {
17            inner: Xz2Encoder::new(Xz2FileFormat::Xz, level),
18        }
19    }
20
21    #[cfg(feature = "xz-parallel")]
22    pub fn parallel(threads: std::num::NonZeroU32, level: Level) -> Self {
23        Self {
24            inner: Xz2Encoder::xz_parallel(level, threads),
25        }
26    }
27}
28
29impl EncodeV2 for XzEncoder {
30    fn encode(
31        &mut self,
32        input: &mut PartialBuffer<&[u8]>,
33        output: &mut WriteBuffer<'_>,
34    ) -> Result<()> {
35        self.inner.encode(input, output)
36    }
37
38    fn flush(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
39        self.inner.flush(output)
40    }
41
42    fn finish(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
43        self.inner.finish(output)
44    }
45}