1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
use crate::driver::ArchiveFile;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
pub struct ZipFile {
pub name: String,
pub datetime: NaiveDateTime,
pub compression_method: u16,
pub compressed_size: u64,
pub size: u64,
pub comment: String,
}
impl ArchiveFile for ZipFile {}
impl ZipFile {
pub(crate) fn new(
name: String,
dos_date: u16,
dos_time: u16,
compression_method: u16,
compressed_size: u64,
size: u64,
comment: String,
) -> Self {
let year = (dos_date >> 9 & 0x7F) + 1980;
let month = dos_date >> 5 & 0xF;
let day = dos_date & 0x1F;
let hour = (dos_time >> 11) & 0x1F;
let minute = (dos_time >> 5) & 0x3F;
let seconds = (dos_time & 0x1F) * 2;
Self {
name,
datetime: NaiveDateTime::new(
NaiveDate::from_ymd_opt(year as i32, month as u32, day as u32).unwrap(),
NaiveTime::from_hms_opt(hour as u32, minute as u32, seconds as u32).unwrap(),
),
compression_method,
compressed_size,
size,
comment,
}
}
}
|