#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
pub const ZSTD_EXTENSION: &str = "zst";
pub const TAR_ZSTD_EXTENSION: &str = "tar.zst";
pub const ZSTD_LABEL: &str = "zstd";
pub const ZSTD_EXTENSIONS: &[&str] = &["zst", "zstd", "tzst", "tar.zst", "tar.zstd"];
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum ZstdFrameKind {
#[default]
Standard,
SingleSegment,
Skippable,
Unknown,
}
impl ZstdFrameKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Standard => "standard",
Self::SingleSegment => "single-segment",
Self::Skippable => "skippable",
Self::Unknown => "unknown",
}
}
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ZstdOptions {
pub level: Option<i32>,
pub checksum: bool,
pub dictionary_id: Option<u32>,
pub frame_kind: ZstdFrameKind,
}
impl ZstdOptions {
#[must_use]
pub const fn new() -> Self {
Self {
level: None,
checksum: false,
dictionary_id: None,
frame_kind: ZstdFrameKind::Standard,
}
}
#[must_use]
pub const fn with_level(mut self, level: i32) -> Self {
self.level = Some(level);
self
}
#[must_use]
pub const fn with_checksum(mut self, checksum: bool) -> Self {
self.checksum = checksum;
self
}
#[must_use]
pub const fn with_dictionary_id(mut self, dictionary_id: u32) -> Self {
self.dictionary_id = Some(dictionary_id);
self
}
#[must_use]
pub const fn with_frame_kind(mut self, frame_kind: ZstdFrameKind) -> Self {
self.frame_kind = frame_kind;
self
}
}
#[cfg(test)]
mod tests {
use super::{TAR_ZSTD_EXTENSION, ZSTD_EXTENSIONS, ZstdFrameKind, ZstdOptions};
#[test]
fn exposes_zstd_labels() {
assert_eq!(TAR_ZSTD_EXTENSION, "tar.zst");
assert!(ZSTD_EXTENSIONS.contains(&"tar.zstd"));
}
#[test]
fn stores_option_metadata() {
let options = ZstdOptions::new()
.with_level(3)
.with_checksum(true)
.with_dictionary_id(42)
.with_frame_kind(ZstdFrameKind::SingleSegment);
assert_eq!(options.level, Some(3));
assert!(options.checksum);
assert_eq!(options.dictionary_id, Some(42));
assert_eq!(options.frame_kind.as_str(), "single-segment");
}
}