1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4pub const ZSTD_EXTENSION: &str = "zst";
8pub const TAR_ZSTD_EXTENSION: &str = "tar.zst";
10pub const ZSTD_LABEL: &str = "zstd";
12pub const ZSTD_EXTENSIONS: &[&str] = &["zst", "zstd", "tzst", "tar.zst", "tar.zstd"];
14
15#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub enum ZstdFrameKind {
18 #[default]
20 Standard,
21 SingleSegment,
23 Skippable,
25 Unknown,
27}
28
29impl ZstdFrameKind {
30 #[must_use]
32 pub const fn as_str(self) -> &'static str {
33 match self {
34 Self::Standard => "standard",
35 Self::SingleSegment => "single-segment",
36 Self::Skippable => "skippable",
37 Self::Unknown => "unknown",
38 }
39 }
40}
41
42#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
44pub struct ZstdOptions {
45 pub level: Option<i32>,
47 pub checksum: bool,
49 pub dictionary_id: Option<u32>,
51 pub frame_kind: ZstdFrameKind,
53}
54
55impl ZstdOptions {
56 #[must_use]
58 pub const fn new() -> Self {
59 Self {
60 level: None,
61 checksum: false,
62 dictionary_id: None,
63 frame_kind: ZstdFrameKind::Standard,
64 }
65 }
66
67 #[must_use]
69 pub const fn with_level(mut self, level: i32) -> Self {
70 self.level = Some(level);
71 self
72 }
73
74 #[must_use]
76 pub const fn with_checksum(mut self, checksum: bool) -> Self {
77 self.checksum = checksum;
78 self
79 }
80
81 #[must_use]
83 pub const fn with_dictionary_id(mut self, dictionary_id: u32) -> Self {
84 self.dictionary_id = Some(dictionary_id);
85 self
86 }
87
88 #[must_use]
90 pub const fn with_frame_kind(mut self, frame_kind: ZstdFrameKind) -> Self {
91 self.frame_kind = frame_kind;
92 self
93 }
94}
95
96#[cfg(test)]
97mod tests {
98 use super::{TAR_ZSTD_EXTENSION, ZSTD_EXTENSIONS, ZstdFrameKind, ZstdOptions};
99
100 #[test]
101 fn exposes_zstd_labels() {
102 assert_eq!(TAR_ZSTD_EXTENSION, "tar.zst");
103 assert!(ZSTD_EXTENSIONS.contains(&"tar.zstd"));
104 }
105
106 #[test]
107 fn stores_option_metadata() {
108 let options = ZstdOptions::new()
109 .with_level(3)
110 .with_checksum(true)
111 .with_dictionary_id(42)
112 .with_frame_kind(ZstdFrameKind::SingleSegment);
113
114 assert_eq!(options.level, Some(3));
115 assert!(options.checksum);
116 assert_eq!(options.dictionary_id, Some(42));
117 assert_eq!(options.frame_kind.as_str(), "single-segment");
118 }
119}