async_zip/spec/
compression.rs1use crate::error::{Result, ZipError};
5
6#[non_exhaustive]
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum Compression {
10 Stored,
11 #[cfg(feature = "deflate")]
12 Deflate,
13 #[cfg(feature = "deflate64")]
14 Deflate64,
15 #[cfg(feature = "bzip2")]
16 Bz,
17 #[cfg(feature = "lzma")]
18 Lzma,
19 #[cfg(feature = "zstd")]
20 Zstd,
21 #[cfg(feature = "xz")]
22 Xz,
23}
24
25impl TryFrom<u16> for Compression {
26 type Error = ZipError;
27
28 fn try_from(value: u16) -> Result<Self> {
31 match value {
32 0 => Ok(Compression::Stored),
33 #[cfg(feature = "deflate")]
34 8 => Ok(Compression::Deflate),
35 #[cfg(feature = "deflate64")]
36 9 => Ok(Compression::Deflate64),
37 #[cfg(feature = "bzip2")]
38 12 => Ok(Compression::Bz),
39 #[cfg(feature = "lzma")]
40 14 => Ok(Compression::Lzma),
41 #[cfg(feature = "zstd")]
42 93 => Ok(Compression::Zstd),
43 #[cfg(feature = "xz")]
44 95 => Ok(Compression::Xz),
45 _ => Err(ZipError::CompressionNotSupported(value)),
46 }
47 }
48}
49
50impl From<&Compression> for u16 {
51 fn from(compression: &Compression) -> u16 {
54 match compression {
55 Compression::Stored => 0,
56 #[cfg(feature = "deflate")]
57 Compression::Deflate => 8,
58 #[cfg(feature = "deflate64")]
59 Compression::Deflate64 => 9,
60 #[cfg(feature = "bzip2")]
61 Compression::Bz => 12,
62 #[cfg(feature = "lzma")]
63 Compression::Lzma => 14,
64 #[cfg(feature = "zstd")]
65 Compression::Zstd => 93,
66 #[cfg(feature = "xz")]
67 Compression::Xz => 95,
68 }
69 }
70}
71
72impl From<Compression> for u16 {
73 fn from(compression: Compression) -> u16 {
74 (&compression).into()
75 }
76}
77
78#[derive(Debug, Clone, Copy)]
80pub enum DeflateOption {
81 Normal,
83
84 Maximum,
86
87 Fast,
89
90 Super,
92
93 Other(i32),
95}