#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
pub const GZIP_EXTENSION: &str = "gz";
pub const TAR_GZIP_EXTENSION: &str = "tar.gz";
pub const GZIP_ENCODING_LABEL: &str = "gzip";
pub const GZIP_MEDIA_TYPE: &str = "application/gzip";
pub const GZIP_EXTENSIONS: &[&str] = &["gz", "gzip", "tgz", "tar.gz"];
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum GzipHeaderMode {
#[default]
Minimal,
FileMetadata,
Unknown,
}
impl GzipHeaderMode {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Minimal => "minimal",
Self::FileMetadata => "file-metadata",
Self::Unknown => "unknown",
}
}
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct GzipOptions {
pub level: Option<u32>,
pub header_mode: GzipHeaderMode,
}
impl GzipOptions {
#[must_use]
pub const fn new() -> Self {
Self {
level: None,
header_mode: GzipHeaderMode::Minimal,
}
}
#[must_use]
pub const fn with_level(mut self, level: u32) -> Self {
self.level = Some(level);
self
}
#[must_use]
pub const fn with_header_mode(mut self, header_mode: GzipHeaderMode) -> Self {
self.header_mode = header_mode;
self
}
}
#[cfg(test)]
mod tests {
use super::{GZIP_ENCODING_LABEL, GZIP_EXTENSIONS, GzipHeaderMode, GzipOptions};
#[test]
fn exposes_gzip_labels() {
assert_eq!(GZIP_ENCODING_LABEL, "gzip");
assert!(GZIP_EXTENSIONS.contains(&"tar.gz"));
}
#[test]
fn stores_option_metadata() {
let options = GzipOptions::new()
.with_level(6)
.with_header_mode(GzipHeaderMode::FileMetadata);
assert_eq!(options.level, Some(6));
assert_eq!(options.header_mode.as_str(), "file-metadata");
}
}