#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
pub const XZ_EXTENSION: &str = "xz";
pub const TAR_XZ_EXTENSION: &str = "tar.xz";
pub const LZMA_LABEL: &str = "lzma";
pub const XZ_EXTENSIONS: &[&str] = &["xz", "lzma", "txz", "tar.xz"];
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum XzCheckType {
None,
Crc32,
#[default]
Crc64,
Sha256,
Unknown,
}
impl XzCheckType {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::None => "none",
Self::Crc32 => "crc32",
Self::Crc64 => "crc64",
Self::Sha256 => "sha256",
Self::Unknown => "unknown",
}
}
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct XzOptions {
pub level: Option<u32>,
pub check_type: XzCheckType,
}
impl XzOptions {
#[must_use]
pub const fn new() -> Self {
Self {
level: None,
check_type: XzCheckType::Crc64,
}
}
#[must_use]
pub const fn with_level(mut self, level: u32) -> Self {
self.level = Some(level);
self
}
#[must_use]
pub const fn with_check_type(mut self, check_type: XzCheckType) -> Self {
self.check_type = check_type;
self
}
}
#[cfg(test)]
mod tests {
use super::{TAR_XZ_EXTENSION, XZ_EXTENSIONS, XzCheckType, XzOptions};
#[test]
fn exposes_xz_labels() {
assert_eq!(TAR_XZ_EXTENSION, "tar.xz");
assert!(XZ_EXTENSIONS.contains(&"txz"));
}
#[test]
fn stores_option_metadata() {
let options = XzOptions::new()
.with_level(6)
.with_check_type(XzCheckType::Sha256);
assert_eq!(options.level, Some(6));
assert_eq!(options.check_type.as_str(), "sha256");
}
}