Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add spec structs #71

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ pub(crate) fn central_header_to_zip_file<R: Read + Seek>(
archive_offset: u64,
) -> ZipResult<ZipFileData> {
let central_header_start = reader.stream_position()?;

let central_header = spec::CentralDirectoryHeader::parse(reader)?;
// Parse central header
let signature = reader.read_u32_le()?;
if signature != spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE {
Expand All @@ -881,11 +881,12 @@ pub(crate) fn central_header_to_zip_file<R: Read + Seek>(
}

/// Parse a central directory entry to collect the information for the file.
fn central_header_to_zip_file_inner<R: Read>(
fn central_header_to_zip_file_inner<R: Read + Seek>(
reader: &mut R,
archive_offset: u64,
central_header_start: u64,
) -> ZipResult<ZipFileData> {
let central_header = spec::CentralDirectoryHeader::parse(reader)?;
let version_made_by = reader.read_u16_le()?;
let _version_to_extract = reader.read_u16_le()?;
let flags = reader.read_u16_le()?;
Expand Down Expand Up @@ -923,29 +924,31 @@ fn central_header_to_zip_file_inner<R: Read>(

// Construct the result
let mut result = ZipFileData {
system: System::from((version_made_by >> 8) as u8),
version_made_by: version_made_by as u8,
encrypted,
using_data_descriptor,
system: System::from_u8((central_header.version_made_by >> 8) as u8),
version_made_by: central_header.version_made_by as u8,
encrypted: central_header.flags.encrypted(),
using_data_descriptor: central_header.flags.using_data_descriptor(),
compression_method: {
#[allow(deprecated)]
CompressionMethod::from_u16(compression_method)
CompressionMethod::from_u16(central_header.compression_method)
},
compression_level: None,
last_modified_time: DateTime::from_msdos(last_mod_date, last_mod_time),
crc32,
compressed_size: compressed_size as u64,
uncompressed_size: uncompressed_size as u64,
last_modified_time: DateTime::from_msdos(
central_header.last_mod_date,
central_header.last_mod_time,
),
crc32: central_header.crc32,
compressed_size: central_header.compressed_size as u64,
uncompressed_size: central_header.uncompressed_size as u64,
file_name,
file_name_raw: file_name_raw.into(),
extra_field: Some(Arc::new(extra_field)),
central_extra_field: None,
file_name_raw: central_header.file_name_raw,
extra_field: Some(Arc::new(central_header.extra_field)),
file_comment,
header_start: offset,
header_start: central_header.offset as u64,
extra_data_start: None,
central_header_start,
data_start: OnceLock::new(),
external_attributes: external_file_attributes,
external_attributes: central_header.external_file_attributes,
large_file: false,
aes_mode: None,
aes_extra_data_start: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/read/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::unstable::LittleEndianReadExt;
use std::fs;
use std::io::{self, Read};
use std::io::{self, Read, Seek};
use std::path::{Path, PathBuf};

use super::{
Expand All @@ -19,7 +19,7 @@ impl<R> ZipStreamReader<R> {
}
}

impl<R: Read> ZipStreamReader<R> {
impl<R: Read + Seek> ZipStreamReader<R> {
fn parse_central_directory(&mut self) -> ZipResult<Option<ZipStreamFileMetadata>> {
// Give archive_offset and central_header_start dummy value 0, since
// they are not used in the output.
Expand Down
Loading
Loading