pub struct CentralDirectoryFileHeader {Show 16 fields
pub version_made_by: u16,
pub version_needed: u16,
pub flag: u16,
pub compression_method: Option<CompressionMethod>,
pub mod_time: u16,
pub mod_date: u16,
pub crc32: u32,
pub compressed_size: u64,
pub uncompressed_size: u64,
pub filename: String,
pub extra_fields: Vec<FileHeaderExtraField>,
pub disk_number: u32,
pub internal_attributes: u16,
pub external_attributes: u32,
pub local_header_offset: u64,
pub header_size: usize,
}Expand description
Represents the result of reading a central directory file header (CDFH)
The layout of this object does not follow the original ZIP CDFH structure
Fields§
§version_made_by: u16§version_needed: u16§flag: u16§compression_method: Option<CompressionMethod>§mod_time: u16§mod_date: u16§crc32: u32§compressed_size: u64§uncompressed_size: u64§filename: String§extra_fields: Vec<FileHeaderExtraField>§disk_number: u32§internal_attributes: u16§external_attributes: u32§local_header_offset: u64§header_size: usizeImplementations§
Source§impl CentralDirectoryFileHeader
impl CentralDirectoryFileHeader
Sourcepub fn from_bytes(data: impl AsRef<[u8]>) -> Option<Self>
pub fn from_bytes(data: impl AsRef<[u8]>) -> Option<Self>
Attempts to read a central directory file header from the provided byte buffer. Returns None if there isn’t enought data
Sourcepub fn is_directory(&self) -> bool
pub fn is_directory(&self) -> bool
Examples found in repository?
examples/archive.rs (line 30)
5fn main() {
6 let output_dir = "unpack";
7 let archive = fs::read("archive.zip").unwrap();
8 let _ = fs::remove_dir_all(output_dir);
9
10 let central_directory = read_cd::from_provider(
11 vec![archive.len()],
12 false,
13 |pos, length| {
14 println!("Requested {length} bytes at {pos}");
15 Ok(archive[(pos.offset)..(pos.offset + length)].to_owned())
16 }
17 ).unwrap().sort();
18
19 let current_file: RefCell<Option<File>> = RefCell::new(None);
20
21 let mut unpacker = ZipUnpacker::new(central_directory, vec![archive.len()]);
22 unpacker.set_callback(|data| {
23 match data {
24 ZipDecodedData::FileHeader(cdfh, _) => {
25 println!();
26
27 let mut path = PathBuf::from(output_dir);
28 path.push(&cdfh.filename);
29
30 if !cdfh.is_directory() {
31 print!("New file: {}", cdfh.filename);
32 io::stdout().flush()?;
33
34 fs::create_dir_all(path.parent().unwrap())?;
35
36 *current_file.borrow_mut() = Some(
37 OpenOptions::new()
38 .create(true)
39 .write(true)
40 .open(path)?
41 );
42 } else {
43 print!("New directory: {}", cdfh.filename);
44 io::stdout().flush()?;
45
46 fs::create_dir_all(path)?;
47 }
48 },
49
50 ZipDecodedData::FileData(data) => {
51 print!(".");
52 io::stdout().flush()?;
53
54 current_file.borrow().as_ref().unwrap().write_all(data)?;
55 }
56 }
57
58 Ok(())
59 });
60
61 unpacker.update(archive).unwrap();
62
63 println!("\nDone!");
64}More examples
examples/multipart.rs (line 42)
5fn main() {
6 let output_dir = "unpack";
7
8 let archives = [
9 "multipart/archive_m.z01",
10 "multipart/archive_m.z02",
11 "multipart/archive_m.z03",
12 "multipart/archive_m.z04",
13 "multipart/archive_m.z05",
14 "multipart/archive_m.z06",
15 "multipart/archive_m.z07",
16 "multipart/archive_m.zip"
17 ].map(fs::read).map(Result::unwrap);
18 let sizes = archives.iter().map(Vec::len).collect::<Vec<_>>();
19
20 let _ = fs::remove_dir_all(output_dir);
21
22 let central_directory = read_cd::from_provider(
23 &sizes,
24 false,
25 |pos, length| {
26 println!("Requested {length} bytes at {pos}");
27 Ok(archives[pos.disk][(pos.offset)..(pos.offset + length)].to_owned())
28 }
29 ).unwrap().sort();
30
31 let current_file: RefCell<Option<File>> = RefCell::new(None);
32
33 let mut unpacker = ZipUnpacker::new(central_directory, sizes);
34 unpacker.set_callback(|data| {
35 match data {
36 ZipDecodedData::FileHeader(cdfh, _) => {
37 println!();
38
39 let mut path = PathBuf::from(output_dir);
40 path.push(&cdfh.filename);
41
42 if !cdfh.is_directory() {
43 print!("New file: {}", cdfh.filename);
44 io::stdout().flush()?;
45
46 fs::create_dir_all(path.parent().unwrap())?;
47
48 *current_file.borrow_mut() = Some(
49 OpenOptions::new()
50 .create(true)
51 .write(true)
52 .open(path)?
53 );
54 } else {
55 print!("New directory: {}", cdfh.filename);
56 io::stdout().flush()?;
57
58 fs::create_dir_all(path)?;
59 }
60 },
61
62 ZipDecodedData::FileData(data) => {
63 print!(".");
64 io::stdout().flush()?;
65
66 current_file.borrow().as_ref().unwrap().write_all(data)?;
67 }
68 }
69
70 Ok(())
71 });
72
73 for archive in archives {
74 unpacker.update(archive).unwrap();
75 }
76
77 println!("\nDone!");
78}Sourcepub fn header_position(&self) -> ZipPosition
pub fn header_position(&self) -> ZipPosition
Returns the ZipPosition of the LFH corresponding to this CDFH
Trait Implementations§
Source§impl Clone for CentralDirectoryFileHeader
impl Clone for CentralDirectoryFileHeader
Source§fn clone(&self) -> CentralDirectoryFileHeader
fn clone(&self) -> CentralDirectoryFileHeader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CentralDirectoryFileHeader
impl RefUnwindSafe for CentralDirectoryFileHeader
impl Send for CentralDirectoryFileHeader
impl Sync for CentralDirectoryFileHeader
impl Unpin for CentralDirectoryFileHeader
impl UnwindSafe for CentralDirectoryFileHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more