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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
use crate::driver::ArchiveFile;
use crate::zip::{ZipError, ZipResult};
use chrono::{DateTime, Local};
pub enum CompressionMethod {
Store,
Deflate,
BZIP2,
LZMA,
ZStd,
XZ,
}
impl CompressionMethod {
pub(crate) fn from_struct_id(id: u16) -> ZipResult<Self> {
match id {
0 => Ok(Self::Store),
8 => Ok(Self::Deflate),
12 => Ok(Self::BZIP2),
14 => Ok(Self::LZMA),
93 => Ok(Self::ZStd),
95 => Ok(Self::XZ),
1..=7 | 9..=11 | 13 | 15..=20 | 94 | 96..=99 => {
Err(ZipError::UnsupportedCompressionMethod.into())
}
21..=92 | 100.. => Err(ZipError::InvalidCompressionMethod.into()),
}
}
}
pub struct ZipFile {
pub compression_method: CompressionMethod,
pub datetime: DateTime<Local>,
pub crc: u32,
pub compressed_size: u64,
pub size: u64,
pub header_pointer: u64,
pub name: String,
pub comment: String,
}
impl ZipFile {
pub fn new(
compression_method: CompressionMethod,
datetime: DateTime<Local>,
crc: u32,
compressed_size: u64,
size: u64,
header_pointer: u64,
name: String,
comment: String,
) -> Self {
Self {
compression_method,
datetime,
crc,
compressed_size,
size,
header_pointer,
name,
comment,
}
}
}
impl ArchiveFile for ZipFile {}
|