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