diff options
| author | igorechek06 <me@igorek.dev> | 2024-08-10 17:58:14 +0900 |
|---|---|---|
| committer | igorechek06 <me@igorek.dev> | 2024-08-10 17:58:14 +0900 |
| commit | 1bb400dcb258f135a3f92f6242e728f0475325c1 (patch) | |
| tree | c71783ceaff073077b7f65705101932ca8f0bbf6 /src/zip/file | |
| parent | 866516ac50851e2827e6aff0a98c444268c566ff (diff) | |
| download | archivator-1bb400dcb258f135a3f92f6242e728f0475325c1.tar.gz archivator-1bb400dcb258f135a3f92f6242e728f0475325c1.zip | |
Unify zip errors
Diffstat (limited to 'src/zip/file')
| -rw-r--r-- | src/zip/file/info.rs | 4 | ||||
| -rw-r--r-- | src/zip/file/read.rs | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/zip/file/info.rs b/src/zip/file/info.rs index 38ea984..93b9f43 100644 --- a/src/zip/file/info.rs +++ b/src/zip/file/info.rs | |||
| @@ -10,7 +10,7 @@ pub enum CompressionMethod { | |||
| 10 | Lzma, | 10 | Lzma, |
| 11 | Zstd, | 11 | Zstd, |
| 12 | Xz, | 12 | Xz, |
| 13 | Unsupported(u16), | 13 | Unsupported, |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | impl CompressionMethod { | 16 | impl CompressionMethod { |
| @@ -23,7 +23,7 @@ impl CompressionMethod { | |||
| 23 | 14 => Self::Lzma, | 23 | 14 => Self::Lzma, |
| 24 | 93 => Self::Zstd, | 24 | 93 => Self::Zstd, |
| 25 | 95 => Self::Xz, | 25 | 95 => Self::Xz, |
| 26 | _ => Self::Unsupported(id), | 26 | _ => Self::Unsupported, |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | } | 29 | } |
diff --git a/src/zip/file/read.rs b/src/zip/file/read.rs index d25655e..567fb75 100644 --- a/src/zip/file/read.rs +++ b/src/zip/file/read.rs | |||
| @@ -116,7 +116,9 @@ impl<Io: Read + Seek> Encryption<IoCursor<Io>> { | |||
| 116 | Aes256::new(key.into()), | 116 | Aes256::new(key.into()), |
| 117 | )?) | 117 | )?) |
| 118 | } | 118 | } |
| 119 | EncryptionMethod::Unsupported => return Err(ZipError::UnsupportedEncryptionMethod), | 119 | EncryptionMethod::Unsupported => { |
| 120 | return Err(ZipError::Unsupported("encryption method")) | ||
| 121 | } | ||
| 120 | }) | 122 | }) |
| 121 | } | 123 | } |
| 122 | } | 124 | } |
| @@ -141,7 +143,7 @@ impl<Io: Read + Seek> Seek for Encryption<Io> { | |||
| 141 | Self::None(io) => io.seek(pos), | 143 | Self::None(io) => io.seek(pos), |
| 142 | _ => Err(IoError::new( | 144 | _ => Err(IoError::new( |
| 143 | IoErrorKind::Unsupported, | 145 | IoErrorKind::Unsupported, |
| 144 | ZipError::EncryptedDataIsUnseekable, | 146 | ZipError::UnseekableFile, |
| 145 | )), | 147 | )), |
| 146 | } | 148 | } |
| 147 | } | 149 | } |
| @@ -182,8 +184,8 @@ impl<Io: Read + Seek> Compression<Io> { | |||
| 182 | } | 184 | } |
| 183 | CompressionMethod::Zstd => Self::Zstd(ZstdDecoder::new(io)?), | 185 | CompressionMethod::Zstd => Self::Zstd(ZstdDecoder::new(io)?), |
| 184 | CompressionMethod::Xz => Self::Xz(XzDecoder::new(io)), | 186 | CompressionMethod::Xz => Self::Xz(XzDecoder::new(io)), |
| 185 | CompressionMethod::Unsupported(id) => { | 187 | CompressionMethod::Unsupported => { |
| 186 | return Err(ZipError::UnsupportedCompressionMethod(id)) | 188 | return Err(ZipError::Unsupported("compression method")); |
| 187 | } | 189 | } |
| 188 | }) | 190 | }) |
| 189 | } | 191 | } |
| @@ -209,7 +211,7 @@ impl<Io: Read + Seek> Seek for Compression<Io> { | |||
| 209 | Compression::Store(io) => io.seek(pos), | 211 | Compression::Store(io) => io.seek(pos), |
| 210 | _ => Err(IoError::new( | 212 | _ => Err(IoError::new( |
| 211 | IoErrorKind::Unsupported, | 213 | IoErrorKind::Unsupported, |
| 212 | ZipError::CompressedDataIsUnseekable, | 214 | ZipError::UnseekableFile, |
| 213 | )), | 215 | )), |
| 214 | } | 216 | } |
| 215 | } | 217 | } |
| @@ -235,7 +237,7 @@ impl<'d, Io: Read + Seek> ZipFileReader<'d, Io> { | |||
| 235 | 237 | ||
| 236 | let buf = io.read_arr::<30>()?; | 238 | let buf = io.read_arr::<30>()?; |
| 237 | if buf[..4] != FILE_HEADER_SIGNATURE { | 239 | if buf[..4] != FILE_HEADER_SIGNATURE { |
| 238 | return Err(ZipError::InvalidFileHeaderSignature); | 240 | return Err(ZipError::InvalidSignature("FileHeader")); |
| 239 | } | 241 | } |
| 240 | 242 | ||
| 241 | let cursor = io.seek(SeekFrom::Start( | 243 | let cursor = io.seek(SeekFrom::Start( |
