| 1 | // Copyright (c) 2021 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | use crate::entry::ZipEntry; |
| 5 | #[cfg(any( |
| 6 | feature = "deflate", |
| 7 | feature = "bzip2", |
| 8 | feature = "zstd", |
| 9 | feature = "lzma", |
| 10 | feature = "xz", |
| 11 | feature = "deflate64" |
| 12 | ))] |
| 13 | use crate::spec::Compression; |
| 14 | |
| 15 | pub(crate) const SPEC_VERSION_MADE_BY: u16 = 63; |
| 16 | |
| 17 | // https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md#443 |
| 18 | pub fn as_needed_to_extract(entry: &ZipEntry) -> u16 { |
| 19 | let mut version = match entry.compression() { |
| 20 | #[cfg(feature = "deflate")] |
| 21 | Compression::Deflate => 20, |
| 22 | #[cfg(feature = "deflate64")] |
| 23 | Compression::Deflate64 => 21, |
| 24 | #[cfg(feature = "bzip2")] |
| 25 | Compression::Bz => 46, |
| 26 | #[cfg(feature = "lzma")] |
| 27 | Compression::Lzma => 63, |
| 28 | _ => 10, |
| 29 | }; |
| 30 | |
| 31 | if let Ok(true) = entry.dir() { |
| 32 | version = std::cmp::max(version, 20); |
| 33 | } |
| 34 | |
| 35 | version |
| 36 | } |
| 37 | |
| 38 | // https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md#442 |
| 39 | pub fn as_made_by() -> u16 { |
| 40 | // Default to UNIX mapping for the moment. |
| 41 | 3 << 8 | SPEC_VERSION_MADE_BY |
| 42 | } |