Skip to content

Commit

Permalink
v0.1.1 + rem unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
plrigaux committed Apr 21, 2023
1 parent 7804cc4 commit fa0851c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "archflow"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
25 changes: 16 additions & 9 deletions src/archive_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::constants::X5455_EXTENDEDTIMESTAMP;
use crate::constants::ZIP64_CENTRAL_DIRECTORY_END_SIGNATURE;

use crate::constants::ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE;
#[cfg(any(feature = "experimental"))]
use crate::error::ArchiveError;
use crate::types::DateTimeCS;
use crate::types::FileCompatibilitySystem;
Expand Down Expand Up @@ -55,22 +56,15 @@ impl ArchiveDescriptor {
self.buffer.extend_from_slice(&val.to_le_bytes());
}

pub fn write_str(&mut self, val: &str) {
self.write_bytes(val.as_bytes());
}

pub fn write_bytes(&mut self, val: &[u8]) {
self.buffer.extend_from_slice(val);
}

pub fn write_bytes_len(&mut self, val: &[u8], max_len: usize) {
self.buffer.extend(val.iter().take(max_len));
}

pub fn write_zeros(&mut self, len: usize) {
self.buffer.resize(self.len() + len, 0);
}

#[cfg(any(feature = "experimental"))]
pub fn finish(self) -> Vec<u8> {
self.buffer
}
Expand All @@ -79,6 +73,7 @@ impl ArchiveDescriptor {
self.buffer.len()
}

#[cfg(any(feature = "experimental"))]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
Expand All @@ -87,6 +82,7 @@ impl ArchiveDescriptor {
&self.buffer
}

#[cfg(any(feature = "experimental"))]
pub fn read_file_descriptor(stream: &[u8]) -> Result<ArchiveFileEntry, ArchiveError> {
let mut indexer = ArchiveDescriptorReader::new();

Expand Down Expand Up @@ -139,11 +135,13 @@ impl ArchiveDescriptor {
}
}

#[cfg(any(feature = "experimental"))]
#[derive(Default)]
pub struct ArchiveDescriptorReader {
index: usize,
}

#[cfg(any(feature = "experimental"))]
macro_rules! read_type {
($self:expr, $stream:expr, $typ:ty) => {{
let upper_bound = $self.index + ::std::mem::size_of::<$typ>();
Expand All @@ -170,6 +168,7 @@ macro_rules! read_type {
}};
}

#[cfg(any(feature = "experimental"))]
impl ArchiveDescriptorReader {
pub fn new() -> ArchiveDescriptorReader {
ArchiveDescriptorReader { index: 0 }
Expand Down Expand Up @@ -260,6 +259,7 @@ pub struct CentralDirectoryEnd {
}

impl CentralDirectoryEnd {
#[cfg(any(feature = "experimental"))]
pub fn zip_file_comment_length(&self) -> u16 {
match &self.archive_comment {
Some(comment) => comment.len() as u16,
Expand Down Expand Up @@ -499,6 +499,7 @@ impl ExtraFieldExtendedTimestamp {
}
}

#[cfg(any(feature = "experimental"))]
pub fn parse_extra_field(
indexer: &mut ArchiveDescriptorReader,
extra_field_as_bytes: &[u8],
Expand Down Expand Up @@ -673,10 +674,13 @@ pub struct ExtraFieldZIP64ExtendedInformation {
impl ExtraFieldZIP64ExtendedInformation {
pub const HEADER_ID: u16 = 0x0001;
const ZIP64_EXTRA_FIELD_SIZE: u16 = 8 * 3 + 4;

#[cfg(any(feature = "experimental"))]
pub fn new(parsed_sized: u16) -> Self {
Self { parsed_sized }
}

#[cfg(any(feature = "experimental"))]
pub fn parse_extra_field(
indexer: &mut ArchiveDescriptorReader,
extra_field_as_bytes: &[u8],
Expand Down Expand Up @@ -794,6 +798,7 @@ pub struct ExtraFieldUnknown {
}

impl ExtraFieldUnknown {
#[cfg(any(feature = "experimental"))]
pub fn parse_extra_field(
indexer: &mut ArchiveDescriptorReader,
extra_field_as_bytes: &[u8],
Expand Down Expand Up @@ -918,6 +923,7 @@ impl ArchiveFileEntry {
FileCompatibilitySystem::from_u8(system_code).to_string()
}

#[cfg(any(feature = "experimental"))]
pub fn get_file_name(&self) -> String {
String::from_utf8_lossy(&self.file_name_as_bytes).to_string()
}
Expand Down Expand Up @@ -950,6 +956,7 @@ impl ArchiveFileEntry {
}
}

#[cfg(any(feature = "experimental"))]
pub fn is_dir(&mut self) {
self.internal_file_attributes &= !ArchiveFileEntry::TEXT_INDICATOR
}
Expand Down Expand Up @@ -1292,7 +1299,7 @@ mod test {
desc.write_u32(uncompressed_size);
desc.write_u16(file_name_len);
desc.write_u16(extra_field_length);
desc.write_str(file_name);
desc.write_bytes(file_name.as_bytes());
let vec = desc.finish();

println!("desc len {:} \n {:02X?}", &vec.len(), &vec);
Expand Down
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use std::mem::size_of;

pub const FILE_HEADER_BASE_SIZE: u64 = (7 * size_of::<u16>() + 4 * size_of::<u32>()) as u64;
pub const ZIP64_DESCRIPTOR_SIZE: u64 = 28;
#[cfg(any(feature = "experimental"))]
pub const CENTRAL_DIRECTORY_ENTRY_BASE_SIZE: u64 =
(11 * size_of::<u16>() + 6 * size_of::<u32>()) as u64;

#[cfg(any(feature = "experimental"))]
pub const END_OF_CENTRAL_DIRECTORY_SIZE: u64 = (5 * size_of::<u16>() + 3 * size_of::<u32>()) as u64;
pub const FILE_HEADER_CRC_OFFSET: u64 = 14;

Expand Down

0 comments on commit fa0851c

Please sign in to comment.