1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4pub const GZIP_EXTENSION: &str = "gz";
8pub const TAR_GZIP_EXTENSION: &str = "tar.gz";
10pub const GZIP_ENCODING_LABEL: &str = "gzip";
12pub const GZIP_MEDIA_TYPE: &str = "application/gzip";
14pub const GZIP_EXTENSIONS: &[&str] = &["gz", "gzip", "tgz", "tar.gz"];
16
17#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
19pub enum GzipHeaderMode {
20 #[default]
22 Minimal,
23 FileMetadata,
25 Unknown,
27}
28
29impl GzipHeaderMode {
30 #[must_use]
32 pub const fn as_str(self) -> &'static str {
33 match self {
34 Self::Minimal => "minimal",
35 Self::FileMetadata => "file-metadata",
36 Self::Unknown => "unknown",
37 }
38 }
39}
40
41#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
43pub struct GzipOptions {
44 pub level: Option<u32>,
46 pub header_mode: GzipHeaderMode,
48}
49
50impl GzipOptions {
51 #[must_use]
53 pub const fn new() -> Self {
54 Self {
55 level: None,
56 header_mode: GzipHeaderMode::Minimal,
57 }
58 }
59
60 #[must_use]
62 pub const fn with_level(mut self, level: u32) -> Self {
63 self.level = Some(level);
64 self
65 }
66
67 #[must_use]
69 pub const fn with_header_mode(mut self, header_mode: GzipHeaderMode) -> Self {
70 self.header_mode = header_mode;
71 self
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 use super::{GZIP_ENCODING_LABEL, GZIP_EXTENSIONS, GzipHeaderMode, GzipOptions};
78
79 #[test]
80 fn exposes_gzip_labels() {
81 assert_eq!(GZIP_ENCODING_LABEL, "gzip");
82 assert!(GZIP_EXTENSIONS.contains(&"tar.gz"));
83 }
84
85 #[test]
86 fn stores_option_metadata() {
87 let options = GzipOptions::new()
88 .with_level(6)
89 .with_header_mode(GzipHeaderMode::FileMetadata);
90
91 assert_eq!(options.level, Some(6));
92 assert_eq!(options.header_mode.as_str(), "file-metadata");
93 }
94}