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)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
fn main() {
let output_dir = "unpack";
let archive = fs::read("archive.zip").unwrap();
let _ = fs::remove_dir_all(output_dir);
let central_directory = read_cd::from_provider(
vec![archive.len()],
false,
|pos, length| {
println!("Requested {length} bytes at {pos}");
Ok(archive[(pos.offset)..(pos.offset + length)].to_owned())
}
).unwrap().sort();
let current_file: RefCell<Option<File>> = RefCell::new(None);
let mut unpacker = ZipUnpacker::new(central_directory, vec![archive.len()]);
unpacker.set_callback(|data| {
match data {
ZipDecodedData::FileHeader(cdfh, _) => {
println!();
let mut path = PathBuf::from(output_dir);
path.push(&cdfh.filename);
if !cdfh.is_directory() {
print!("New file: {}", cdfh.filename);
io::stdout().flush()?;
fs::create_dir_all(path.parent().unwrap())?;
*current_file.borrow_mut() = Some(
OpenOptions::new()
.create(true)
.write(true)
.open(path)?
);
} else {
print!("New directory: {}", cdfh.filename);
io::stdout().flush()?;
fs::create_dir_all(path)?;
}
},
ZipDecodedData::FileData(data) => {
print!(".");
io::stdout().flush()?;
current_file.borrow().as_ref().unwrap().write_all(data)?;
}
}
Ok(())
});
unpacker.update(archive).unwrap();
println!("\nDone!");
}More examples
examples/multipart.rs (line 42)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn main() {
let output_dir = "unpack";
let archives = [
"multipart/archive_m.z01",
"multipart/archive_m.z02",
"multipart/archive_m.z03",
"multipart/archive_m.z04",
"multipart/archive_m.z05",
"multipart/archive_m.z06",
"multipart/archive_m.z07",
"multipart/archive_m.zip"
].map(fs::read).map(Result::unwrap);
let sizes = archives.iter().map(Vec::len).collect::<Vec<_>>();
let _ = fs::remove_dir_all(output_dir);
let central_directory = read_cd::from_provider(
&sizes,
false,
|pos, length| {
println!("Requested {length} bytes at {pos}");
Ok(archives[pos.disk][(pos.offset)..(pos.offset + length)].to_owned())
}
).unwrap().sort();
let current_file: RefCell<Option<File>> = RefCell::new(None);
let mut unpacker = ZipUnpacker::new(central_directory, sizes);
unpacker.set_callback(|data| {
match data {
ZipDecodedData::FileHeader(cdfh, _) => {
println!();
let mut path = PathBuf::from(output_dir);
path.push(&cdfh.filename);
if !cdfh.is_directory() {
print!("New file: {}", cdfh.filename);
io::stdout().flush()?;
fs::create_dir_all(path.parent().unwrap())?;
*current_file.borrow_mut() = Some(
OpenOptions::new()
.create(true)
.write(true)
.open(path)?
);
} else {
print!("New directory: {}", cdfh.filename);
io::stdout().flush()?;
fs::create_dir_all(path)?;
}
},
ZipDecodedData::FileData(data) => {
print!(".");
io::stdout().flush()?;
current_file.borrow().as_ref().unwrap().write_all(data)?;
}
}
Ok(())
});
for archive in archives {
unpacker.update(archive).unwrap();
}
println!("\nDone!");
}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 copy 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 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