aboutsummaryrefslogtreecommitdiff
path: root/src/zip/file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/zip/file.rs')
-rw-r--r--src/zip/file.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/zip/file.rs b/src/zip/file.rs
new file mode 100644
index 0000000..3b63c2a
--- /dev/null
+++ b/src/zip/file.rs
@@ -0,0 +1,45 @@
1use crate::driver::ArchiveFile;
2use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
3
4pub struct ZipFile {
5 pub name: String,
6 pub datetime: NaiveDateTime,
7 pub compression_method: u16,
8 pub compressed_size: u64,
9 pub size: u64,
10 pub comment: String,
11}
12
13impl ArchiveFile for ZipFile {}
14
15impl ZipFile {
16 pub fn new(
17 name: String,
18 dos_date: u16,
19 dos_time: u16,
20 compression_method: u16,
21 compressed_size: u64,
22 size: u64,
23 comment: String,
24 ) -> Self {
25 let year = (dos_date >> 9 & 0x7F) + 1980;
26 let month = dos_date >> 5 & 0xF;
27 let day = dos_date & 0x1F;
28
29 let hour = (dos_time >> 11) & 0x1F;
30 let minute = (dos_time >> 5) & 0x3F;
31 let seconds = (dos_time & 0x1F) * 2;
32
33 Self {
34 name,
35 datetime: NaiveDateTime::new(
36 NaiveDate::from_ymd_opt(year as i32, month as u32, day as u32).unwrap(),
37 NaiveTime::from_hms_opt(hour as u32, minute as u32, seconds as u32).unwrap(),
38 ),
39 compression_method,
40 compressed_size,
41 size,
42 comment,
43 }
44 }
45}