diff --git a/src/compression.rs b/src/compression.rs index 3183e851..5fdde070 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -10,7 +10,7 @@ use std::fmt; /// /// When creating ZIP files, you may choose the method to use with /// [`zip::write::FileOptions::compression_method`] -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum CompressionMethod { /// Store the file as is Stored, @@ -25,18 +25,53 @@ pub enum CompressionMethod { #[cfg(feature = "bzip2")] Bzip2, /// Unsupported compression method - #[deprecated( - since = "0.5.7", - note = "implementation details are being removed from the public API" - )] + #[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 { + pub const STORE: Self = CompressionMethod::Stored; + pub const SHRINK: Self = CompressionMethod::Unsupported(1); + pub const REDUCE_1: Self = CompressionMethod::Unsupported(2); + pub const REDUCE_2: Self = CompressionMethod::Unsupported(3); + pub const REDUCE_3: Self = CompressionMethod::Unsupported(4); + pub const REDUCE_4: Self = CompressionMethod::Unsupported(5); + pub const IMPLODE: Self = CompressionMethod::Unsupported(6); + #[cfg(any( + feature = "deflate", + feature = "deflate-miniz", + feature = "deflate-zlib" + ))] + pub const DEFLATE: Self = CompressionMethod::Deflated; + #[cfg(not(any( + feature = "deflate", + feature = "deflate-miniz", + feature = "deflate-zlib" + )))] + pub const DEFLATE: Self = CompressionMethod::Unsupported(8); + pub const DEFLATE64: Self = CompressionMethod::Unsupported(9); + pub const PKWARE_IMPLODE: Self = CompressionMethod::Unsupported(10); + #[cfg(feature = "bzip2")] + pub const BZIP2: Self = CompressionMethod::Bzip2; + #[cfg(not(feature = "bzip2"))] + pub const BZIP2: Self = CompressionMethod::Unsupported(12); + pub const LZMA: Self = CompressionMethod::Unsupported(14); + pub const IBM_ZOS_CMPSC: Self = CompressionMethod::Unsupported(16); + pub const IBM_TERSE: Self = CompressionMethod::Unsupported(18); + pub const ZSTD_DEPRECATED: Self = CompressionMethod::Unsupported(20); + pub const ZSTD: Self = CompressionMethod::Unsupported(93); + pub const MP3: Self = CompressionMethod::Unsupported(94); + pub const XZ: Self = CompressionMethod::Unsupported(95); + pub const JPEG: Self = CompressionMethod::Unsupported(96); + pub const WAVPACK: Self = CompressionMethod::Unsupported(97); + pub const PPMD: Self = CompressionMethod::Unsupported(98); +} impl CompressionMethod { /// Converts an u16 to its corresponding CompressionMethod #[deprecated( since = "0.5.7", - note = "implementation details are being removed from the public API" + note = "use a constant to construct a compression method" )] pub fn from_u16(val: u16) -> CompressionMethod { #[allow(deprecated)] @@ -58,7 +93,7 @@ impl CompressionMethod { /// Converts a CompressionMethod to a u16 #[deprecated( since = "0.5.7", - note = "implementation details are being removed from the public API" + note = "to match on other compression methods, use a constant" )] pub fn to_u16(self) -> u16 { #[allow(deprecated)]