| 1 | // Copyright (c) 2021 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | use craterust-analyzer cargo async_zip 0.0.18 crate/::errorrust-analyzer cargo async_zip 0.0.18 error/::{Resultrust-analyzer cargo async_zip 0.0.18 error/Result#, ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#}; |
| 5 | |
| 6 | #[cfg(any(feature = "deflate", feature = "bzip2", feature = "zstd", feature = "lzma", feature = "xz"))] |
| 7 | use async_compressionrust-analyzer cargo async-compression 0.4.27 crate/::Levelrust-analyzer cargo async-compression 0.4.27 Level#; |
| 8 | |
| 9 | /// A compression method supported by this crate. |
| 10 | #[non_exhaustive] |
| 11 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 12 | pub enum Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression# { |
| 13 | Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored#, |
| 14 | #[cfg(feature = "deflate")] |
| 15 | Deflaterust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Deflate#, |
| 16 | #[cfg(feature = "deflate64")] |
| 17 | Deflate64, |
| 18 | #[cfg(feature = "bzip2")] |
| 19 | Bzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Bz#, |
| 20 | #[cfg(feature = "lzma")] |
| 21 | Lzmarust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Lzma#, |
| 22 | #[cfg(feature = "zstd")] |
| 23 | Zstdrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Zstd#, |
| 24 | #[cfg(feature = "xz")] |
| 25 | Xzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Xz#, |
| 26 | } |
| 27 | |
| 28 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<u16> for Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression# { |
| 29 | type Errorrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[Compression][`TryFrom<u16>`]Error# = ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#; |
| 30 | |
| 31 | // Convert a u16 stored with little endianness into a supported compression method. |
| 32 | // https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md#445 |
| 33 | fn try_fromrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[Compression][`TryFrom<u16>`]try_from().(value: u16) -> Resultrust-analyzer cargo async_zip 0.0.18 error/Result#<Selfrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[Compression][`TryFrom<u16>`]> { |
| 34 | match value { |
| 35 | 0 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored#), |
| 36 | #[cfg(feature = "deflate")] |
| 37 | 8 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Deflaterust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Deflate#), |
| 38 | #[cfg(feature = "deflate64")] |
| 39 | 9 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Deflate64), |
| 40 | #[cfg(feature = "bzip2")] |
| 41 | 12 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Bzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Bz#), |
| 42 | #[cfg(feature = "lzma")] |
| 43 | 14 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Lzmarust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Lzma#), |
| 44 | #[cfg(feature = "zstd")] |
| 45 | 93 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Zstdrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Zstd#), |
| 46 | #[cfg(feature = "xz")] |
| 47 | 95 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Xzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Xz#), |
| 48 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#::CompressionNotSupportedrust-analyzer cargo async_zip 0.0.18 error/ZipError#CompressionNotSupported#(value)), |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#> for u16 { |
| 54 | // Convert a supported compression method into its relevant u16 stored with little endianness. |
| 55 | // https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md#445 |
| 56 | fn fromrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[u16][`From<&Compression>`]from().(compression: &Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#) -> u16 { |
| 57 | match compression { |
| 58 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored# => 0, |
| 59 | #[cfg(feature = "deflate")] |
| 60 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Deflaterust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Deflate# => 8, |
| 61 | #[cfg(feature = "deflate64")] |
| 62 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Deflate64 => 9, |
| 63 | #[cfg(feature = "bzip2")] |
| 64 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Bzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Bz# => 12, |
| 65 | #[cfg(feature = "lzma")] |
| 66 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Lzmarust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Lzma# => 14, |
| 67 | #[cfg(feature = "zstd")] |
| 68 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Zstdrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Zstd# => 93, |
| 69 | #[cfg(feature = "xz")] |
| 70 | Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Xzrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Xz# => 95, |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#> for u16 { |
| 76 | fn fromrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[u16][`From<Compression>`]from().(compression: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#) -> u16 { |
| 77 | (&compression).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /// Level of compression data should be compressed with for deflate. |
| 82 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 83 | pub enum DeflateOptionrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption# { |
| 84 | // Normal (-en) compression option was used. |
| 85 | Normalrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Normal#, |
| 86 | |
| 87 | // Maximum (-exx/-ex) compression option was used. |
| 88 | Maximumrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Maximum#, |
| 89 | |
| 90 | // Fast (-ef) compression option was used. |
| 91 | Fastrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Fast#, |
| 92 | |
| 93 | // Super Fast (-es) compression option was used. |
| 94 | Superrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Super#, |
| 95 | |
| 96 | /// Other implementation defined level. |
| 97 | Otherrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Other#(i32), |
| 98 | } |
| 99 | |
| 100 | #[cfg(any(feature = "deflate", feature = "bzip2", feature = "zstd", feature = "lzma", feature = "xz"))] |
| 101 | impl DeflateOptionrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption# { |
| 102 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn into_levelrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[DeflateOption]into_level().(self) -> Levelrust-analyzer cargo async-compression 0.4.27 Level# { |
| 103 | // FIXME: There's no clear documentation on what these specific levels defined in the ZIP specification relate |
| 104 | // to. We want to be compatible with any other library, and not specific to `async_compression`'s levels. |
| 105 | if let Selfrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[DeflateOption]::Otherrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#Other#(l) = self { |
| 106 | Levelrust-analyzer cargo async-compression 0.4.27 Level#::Preciserust-analyzer cargo async-compression 0.4.27 Level#Precise#(l) |
| 107 | } else { |
| 108 | Levelrust-analyzer cargo async-compression 0.4.27 Level#::Defaultrust-analyzer cargo async-compression 0.4.27 Level#Default# |
| 109 | } |
| 110 | } |
| 111 | } |