1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4pub const XZ_EXTENSION: &str = "xz";
8pub const TAR_XZ_EXTENSION: &str = "tar.xz";
10pub const LZMA_LABEL: &str = "lzma";
12pub const XZ_EXTENSIONS: &[&str] = &["xz", "lzma", "txz", "tar.xz"];
14
15#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub enum XzCheckType {
18 None,
20 Crc32,
22 #[default]
24 Crc64,
25 Sha256,
27 Unknown,
29}
30
31impl XzCheckType {
32 #[must_use]
34 pub const fn as_str(self) -> &'static str {
35 match self {
36 Self::None => "none",
37 Self::Crc32 => "crc32",
38 Self::Crc64 => "crc64",
39 Self::Sha256 => "sha256",
40 Self::Unknown => "unknown",
41 }
42 }
43}
44
45#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
47pub struct XzOptions {
48 pub level: Option<u32>,
50 pub check_type: XzCheckType,
52}
53
54impl XzOptions {
55 #[must_use]
57 pub const fn new() -> Self {
58 Self {
59 level: None,
60 check_type: XzCheckType::Crc64,
61 }
62 }
63
64 #[must_use]
66 pub const fn with_level(mut self, level: u32) -> Self {
67 self.level = Some(level);
68 self
69 }
70
71 #[must_use]
73 pub const fn with_check_type(mut self, check_type: XzCheckType) -> Self {
74 self.check_type = check_type;
75 self
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::{TAR_XZ_EXTENSION, XZ_EXTENSIONS, XzCheckType, XzOptions};
82
83 #[test]
84 fn exposes_xz_labels() {
85 assert_eq!(TAR_XZ_EXTENSION, "tar.xz");
86 assert!(XZ_EXTENSIONS.contains(&"txz"));
87 }
88
89 #[test]
90 fn stores_option_metadata() {
91 let options = XzOptions::new()
92 .with_level(6)
93 .with_check_type(XzCheckType::Sha256);
94
95 assert_eq!(options.level, Some(6));
96 assert_eq!(options.check_type.as_str(), "sha256");
97 }
98}