#[allow(deprecated)] /// Identifies the storage format used to compress a file within a ZIP archive. /// /// Each file's compression method is stored alongside it, allowing the /// contents to be read without context. /// /// When creating ZIP files, you may choose the method to use with /// [`crate::write::FileOptions::compression_method`] #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(fuzzing, derive(arbitrary::Arbitrary))] #[non_exhaustive] pubenum CompressionMethod { /// Store the file as is
Stored, /// Compress the file using Deflate #[cfg(feature = "_deflate-any")]
Deflated, /// Compress the file using Deflate64. /// Decoding deflate64 is supported but encoding deflate64 is not supported. #[cfg(feature = "deflate64")]
Deflate64, /// Compress the file using BZIP2 #[cfg(feature = "bzip2")]
Bzip2, /// Encrypted using AES. /// /// The actual compression method has to be taken from the AES extra data field /// or from `ZipFileData`. #[cfg(feature = "aes-crypto")]
Aes, /// Compress the file using ZStandard #[cfg(feature = "zstd")]
Zstd, /// Compress the file using LZMA #[cfg(feature = "lzma")]
Lzma, /// Unsupported compression method #[cfg_attr(
not(fuzzing),
deprecated(since = "0.5.7", note = "use the constants instead")
)]
Unsupported(u16),
} #[allow(deprecated, missing_docs)] /// All compression methods defined for the ZIP format impl CompressionMethod { pubconst STORE: Self = CompressionMethod::Stored; pubconst SHRINK: Self = CompressionMethod::Unsupported(1); pubconst REDUCE_1: Self = CompressionMethod::Unsupported(2); pubconst REDUCE_2: Self = CompressionMethod::Unsupported(3); pubconst REDUCE_3: Self = CompressionMethod::Unsupported(4); pubconst REDUCE_4: Self = CompressionMethod::Unsupported(5); pubconst IMPLODE: Self = CompressionMethod::Unsupported(6); #[cfg(feature = "_deflate-any")] pubconst DEFLATE: Self = CompressionMethod::Deflated; #[cfg(not(feature = "_deflate-any"))] pubconst DEFLATE: Self = CompressionMethod::Unsupported(8); #[cfg(feature = "deflate64")] pubconst DEFLATE64: Self = CompressionMethod::Deflate64; #[cfg(not(feature = "deflate64"))] pubconst DEFLATE64: Self = CompressionMethod::Unsupported(9); pubconst PKWARE_IMPLODE: Self = CompressionMethod::Unsupported(10); #[cfg(feature = "bzip2")] pubconst BZIP2: Self = CompressionMethod::Bzip2; #[cfg(not(feature = "bzip2"))] pubconst BZIP2: Self = CompressionMethod::Unsupported(12); #[cfg(not(feature = "lzma"))] pubconst LZMA: Self = CompressionMethod::Unsupported(14); #[cfg(feature = "lzma")] pubconst LZMA: Self = CompressionMethod::Lzma; pubconst IBM_ZOS_CMPSC: Self = CompressionMethod::Unsupported(16); pubconst IBM_TERSE: Self = CompressionMethod::Unsupported(18); pubconst ZSTD_DEPRECATED: Self = CompressionMethod::Unsupported(20); #[cfg(feature = "zstd")] pubconst ZSTD: Self = CompressionMethod::Zstd; #[cfg(not(feature = "zstd"))] pubconst ZSTD: Self = CompressionMethod::Unsupported(93); pubconst MP3: Self = CompressionMethod::Unsupported(94); pubconst XZ: Self = CompressionMethod::Unsupported(95); pubconst JPEG: Self = CompressionMethod::Unsupported(96); pubconst WAVPACK: Self = CompressionMethod::Unsupported(97); pubconst PPMD: Self = CompressionMethod::Unsupported(98); #[cfg(feature = "aes-crypto")] pubconst AES: Self = CompressionMethod::Aes; #[cfg(not(feature = "aes-crypto"))] pubconst AES: Self = CompressionMethod::Unsupported(99);
} impl CompressionMethod { pub(crate) constfn parse_from_u16(val: u16) -> Self { match val { 0 => CompressionMethod::Stored, #[cfg(feature = "_deflate-any")] 8 => CompressionMethod::Deflated, #[cfg(feature = "deflate64")] 9 => CompressionMethod::Deflate64, #[cfg(feature = "bzip2")] 12 => CompressionMethod::Bzip2, #[cfg(feature = "lzma")] 14 => CompressionMethod::Lzma, #[cfg(feature = "zstd")] 93 => CompressionMethod::Zstd, #[cfg(feature = "aes-crypto")] 99 => CompressionMethod::Aes, #[allow(deprecated)]
v => CompressionMethod::Unsupported(v),
}
}
/// Converts a u16 to its corresponding CompressionMethod #[deprecated(
since = "0.5.7",
note = "use a constant to construct a compression method"
)] pubconstfn from_u16(val: u16) -> CompressionMethod { Self::parse_from_u16(val)
}
/// Converts a CompressionMethod to a u16 #[deprecated(
since = "0.5.7",
note = "to match on other compression methods, use a constant"
)] pubconstfn to_u16(self) -> u16 { self.serialize_to_u16()
}
}
impl fmt::Display for CompressionMethod { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Just duplicate what the Debug format looks like, i.e, the enum key:
write!(f, "{self:?}")
}
}
/// The compression methods which have been implemented. pubconst SUPPORTED_COMPRESSION_METHODS: &[CompressionMethod] = &[
CompressionMethod::Stored, #[cfg(feature = "_deflate-any")]
CompressionMethod::Deflated, #[cfg(feature = "deflate64")]
CompressionMethod::Deflate64, #[cfg(feature = "bzip2")]
CompressionMethod::Bzip2, #[cfg(feature = "zstd")]
CompressionMethod::Zstd,
];
#[cfg(test)] mod test { usesuper::{CompressionMethod, SUPPORTED_COMPRESSION_METHODS};
#[test] fn from_eq_to() { for v in0..(u16::MAX as u32 + 1) { let from = CompressionMethod::parse_from_u16(v as u16); let to = from.serialize_to_u16() as u32;
assert_eq!(v, to);
}
}
#[test] fn to_eq_from() { fn check_match(method: CompressionMethod) { let to = method.serialize_to_u16(); let from = CompressionMethod::parse_from_u16(to); let back = from.serialize_to_u16();
assert_eq!(to, back);
}
for &method in SUPPORTED_COMPRESSION_METHODS {
check_match(method);
}
}
#[test] fn to_display_fmt() { fn check_match(method: CompressionMethod) { let debug_str = format!("{method:?}"); let display_str = format!("{method}");
assert_eq!(debug_str, display_str);
}
for &method in SUPPORTED_COMPRESSION_METHODS {
check_match(method);
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.