Compare commits
4
Commits
1bebf10db2
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61a8758082 | ||
|
|
3ef19612d7 | ||
|
|
b40a156b13 | ||
|
|
ac313d1a7d |
No files matched your search
+7
-15
@@ -9,32 +9,24 @@ pub struct BaseHeader {
|
||||
os: Os,
|
||||
}
|
||||
|
||||
impl BaseHeader {
|
||||
const SIZE: usize = 10;
|
||||
|
||||
fn to_bytes(self) -> [u8; Self::SIZE] {
|
||||
let mtime: [u8; 4] = self.last_modified.into();
|
||||
impl From<BaseHeader> for [u8; 10] {
|
||||
fn from(header: BaseHeader) -> Self {
|
||||
let mtime: [u8; 4] = header.last_modified.into();
|
||||
[
|
||||
ID1,
|
||||
ID2,
|
||||
self.compression_method.into(),
|
||||
self.flags.0,
|
||||
header.compression_method.into(),
|
||||
header.flags.0,
|
||||
mtime[0],
|
||||
mtime[1],
|
||||
mtime[2],
|
||||
mtime[3],
|
||||
self.extra_flags.0,
|
||||
self.os.into(),
|
||||
header.extra_flags.0,
|
||||
header.os.into(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BaseHeader> for [u8; 10] {
|
||||
fn from(header: BaseHeader) -> Self {
|
||||
header.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
pub enum CompressionMethod {
|
||||
Deflate,
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,14 +25,14 @@ impl From<ExtraFieldHeader> for Vec<u8> {
|
||||
}
|
||||
|
||||
impl From<ExtraSubField> for Vec<u8> {
|
||||
fn from(extra_sub_field: ExtraSubField) -> Self {
|
||||
fn from(mut extra_sub_field: ExtraSubField) -> Self {
|
||||
let mut result = Vec::new();
|
||||
let len = extra_sub_field.field.len().to_le_bytes();
|
||||
result.push(extra_sub_field.subfield_id1);
|
||||
result.push(extra_sub_field.subfield_id2);
|
||||
result.push(len[0]);
|
||||
result.push(len[1]);
|
||||
result.append(&mut extra_sub_field.field.clone());
|
||||
result.append(&mut extra_sub_field.field);
|
||||
result
|
||||
}
|
||||
}
|
||||
+15
-1
@@ -1,6 +1,20 @@
|
||||
mod crc32;
|
||||
mod header;
|
||||
|
||||
struct GzipFile {
|
||||
pub struct GzipFile {
|
||||
header: header::Header,
|
||||
compressed_data: Vec<u8>,
|
||||
crc32: u32,
|
||||
input_size: u32,
|
||||
}
|
||||
|
||||
impl From<GzipFile> for Vec<u8> {
|
||||
fn from(mut gzip_file: GzipFile) -> Self {
|
||||
let mut result = Vec::new();
|
||||
result.append(&mut gzip_file.header.into());
|
||||
result.append(&mut gzip_file.compressed_data);
|
||||
result.extend(gzip_file.crc32.to_le_bytes());
|
||||
result.extend(gzip_file.input_size.to_le_bytes());
|
||||
result
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user