diff options
Diffstat (limited to 'src/zip/driver.rs')
| -rw-r--r-- | src/zip/driver.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs index 650344e..0db845d 100644 --- a/src/zip/driver.rs +++ b/src/zip/driver.rs | |||
| @@ -1,27 +1,27 @@ | |||
| 1 | use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; | 1 | use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; |
| 2 | use crate::zip::file::{BitFlag, CompressionMethod}; | ||
| 3 | use crate::zip::structs::{deserialize, EOCDR64Locator, ExtraHeader, CDR, EOCDR, EOCDR64}; | 2 | use crate::zip::structs::{deserialize, EOCDR64Locator, ExtraHeader, CDR, EOCDR, EOCDR64}; |
| 4 | use crate::zip::{ZipError, ZipFile, ZipResult}; | 3 | use crate::zip::{BitFlag, CompressionMethod, ZipError, ZipFile, ZipFileInfo, ZipResult}; |
| 5 | use chrono::{Local, NaiveDate, NaiveDateTime, NaiveTime}; | 4 | use chrono::{Local, NaiveDate, NaiveDateTime, NaiveTime}; |
| 6 | use std::collections::HashMap as Map; | 5 | use std::collections::HashMap as Map; |
| 7 | use std::io::{Read, Seek, SeekFrom, Write}; | 6 | use std::io::{Read, Seek, SeekFrom, Write}; |
| 8 | 7 | ||
| 9 | pub struct Zip<IO> { | 8 | pub struct Zip<Io> { |
| 10 | io: IO, | 9 | io: Io, |
| 11 | 10 | ||
| 12 | files: Map<String, ZipFile>, | 11 | files: Map<String, ZipFileInfo>, |
| 13 | comment: String, | 12 | comment: String, |
| 14 | } | 13 | } |
| 15 | 14 | ||
| 16 | impl<IO> Driver for Zip<IO> { | 15 | impl<Io> Driver for Zip<Io> { |
| 17 | type Error = ZipError; | 16 | type Error = ZipError; |
| 18 | 17 | ||
| 19 | type IO = IO; | 18 | type Io = Io; |
| 20 | type File = ZipFile; | 19 | type FileDriver<'d> = ZipFile<'d, Self::Io> where Self::Io: 'd; |
| 20 | type FileInfo = ZipFileInfo; | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | impl<IO: Read + Seek> ArchiveRead for Zip<IO> { | 23 | impl<Io: Read + Seek> ArchiveRead for Zip<Io> { |
| 24 | fn read(mut io: Self::IO) -> ZipResult<Self> { | 24 | fn read(mut io: Self::Io) -> ZipResult<Self> { |
| 25 | // Search eocdr | 25 | // Search eocdr |
| 26 | let limit = 65557.min(io.seek(SeekFrom::End(0))?) as i64; | 26 | let limit = 65557.min(io.seek(SeekFrom::End(0))?) as i64; |
| 27 | let start = io.seek(SeekFrom::End(-limit))?; | 27 | let start = io.seek(SeekFrom::End(-limit))?; |
| @@ -137,7 +137,7 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> { | |||
| 137 | 137 | ||
| 138 | files.insert( | 138 | files.insert( |
| 139 | name.clone(), | 139 | name.clone(), |
| 140 | ZipFile::new( | 140 | ZipFileInfo::new( |
| 141 | CompressionMethod::from_struct_id(cdr.compression_method)?, | 141 | CompressionMethod::from_struct_id(cdr.compression_method)?, |
| 142 | BitFlag::new(cdr.bit_flag), | 142 | BitFlag::new(cdr.bit_flag), |
| 143 | NaiveDateTime::new( | 143 | NaiveDateTime::new( |
| @@ -169,23 +169,27 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> { | |||
| 169 | Ok(Self { io, files, comment }) | 169 | Ok(Self { io, files, comment }) |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | fn files(&self) -> Vec<&Self::File> { | 172 | fn files(&self) -> Vec<&Self::FileInfo> { |
| 173 | let mut files: Vec<&Self::File> = self.files.values().collect(); | 173 | let mut files: Vec<&Self::FileInfo> = self.files.values().collect(); |
| 174 | files.sort_by_key(|f| &f.name); | 174 | files.sort_by_key(|f| &f.name); |
| 175 | files | 175 | files |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | fn get_file(&self, name: &str) -> Option<&Self::File> { | 178 | fn get_file_info(&self, name: &str) -> Option<&Self::FileInfo> { |
| 179 | self.files.get(name) | 179 | self.files.get(name) |
| 180 | } | 180 | } |
| 181 | |||
| 182 | fn get_file_reader<'d>(&'d mut self, name: &str) -> Option<Self::FileDriver<'d>> { | ||
| 183 | Some(ZipFile::new(&mut self.io, self.files.get(name)?).unwrap()) | ||
| 184 | } | ||
| 181 | } | 185 | } |
| 182 | 186 | ||
| 183 | impl<IO: Read + Seek> Zip<IO> { | 187 | impl<Io: Read + Seek> Zip<Io> { |
| 184 | pub fn comment(&self) -> &String { | 188 | pub fn comment(&self) -> &String { |
| 185 | &self.comment | 189 | &self.comment |
| 186 | } | 190 | } |
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | impl<IO: Read + Write + Seek> ArchiveWrite for Zip<IO> {} | 193 | impl<Io: Read + Write + Seek> ArchiveWrite for Zip<Io> {} |
| 190 | 194 | ||
| 191 | impl<IO: Read + Write + Seek> Zip<IO> {} | 195 | impl<Io: Read + Write + Seek> Zip<Io> {} |
