Compare commits

..
3 Commits
3 changed files with 18 additions and 24 deletions

No files matched your search

+15 -7
View File
@@ -9,24 +9,32 @@ pub struct BaseHeader {
os: Os, os: Os,
} }
impl From<BaseHeader> for [u8; 10] { impl BaseHeader {
fn from(header: BaseHeader) -> Self { const SIZE: usize = 10;
let mtime: [u8; 4] = header.last_modified.into();
fn to_bytes(self) -> [u8; Self::SIZE] {
let mtime: [u8; 4] = self.last_modified.into();
[ [
ID1, ID1,
ID2, ID2,
header.compression_method.into(), self.compression_method.into(),
header.flags.0, self.flags.0,
mtime[0], mtime[0],
mtime[1], mtime[1],
mtime[2], mtime[2],
mtime[3], mtime[3],
header.extra_flags.0, self.extra_flags.0,
header.os.into(), self.os.into(),
] ]
} }
} }
impl From<BaseHeader> for [u8; 10] {
fn from(header: BaseHeader) -> Self {
header.to_bytes()
}
}
pub enum CompressionMethod { pub enum CompressionMethod {
Deflate, Deflate,
} }
+2 -2
View File
@@ -25,14 +25,14 @@ impl From<ExtraFieldHeader> for Vec<u8> {
} }
impl From<ExtraSubField> for Vec<u8> { impl From<ExtraSubField> for Vec<u8> {
fn from(mut extra_sub_field: ExtraSubField) -> Self { fn from(extra_sub_field: ExtraSubField) -> Self {
let mut result = Vec::new(); let mut result = Vec::new();
let len = extra_sub_field.field.len().to_le_bytes(); let len = extra_sub_field.field.len().to_le_bytes();
result.push(extra_sub_field.subfield_id1); result.push(extra_sub_field.subfield_id1);
result.push(extra_sub_field.subfield_id2); result.push(extra_sub_field.subfield_id2);
result.push(len[0]); result.push(len[0]);
result.push(len[1]); result.push(len[1]);
result.append(&mut extra_sub_field.field); result.append(&mut extra_sub_field.field.clone());
result result
} }
} }
+1 -15
View File
@@ -1,20 +1,6 @@
mod crc32; mod crc32;
mod header; mod header;
pub struct GzipFile { struct GzipFile {
header: header::Header, 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
}
} }