zip/format/mod.rs
1//! Zip format
2
3pub mod aes;
4pub mod blocks;
5pub mod compression;
6pub mod data_descriptor;
7pub mod extra_fields;
8pub(crate) mod find_central_directory;
9pub mod flags;
10pub(crate) mod functions;
11pub mod magic;
12pub mod system;
13
14/// ffi for Windows
15pub mod ffi {
16 /// Regular
17 pub const S_IFREG: u32 = 0b1000_0000_0000_0000; // 0o100_000
18 /// Directory
19 pub const S_IFDIR: u32 = 0b0100_0000_0000_0000; // 0o040_000
20 /// Symbolic link
21 pub const S_IFLNK: u32 = 0b1010_0000_0000_0000; // 0o120_000
22}
23
24// re-export
25pub(crate) use find_central_directory::find_central_directory_end;
26
27/// The file size at which a ZIP64 record becomes necessary.
28///
29/// If a file larger than this threshold attempts to be written, compressed or uncompressed, and
30/// [`FileOptions::large_file()`](crate::write::FileOptions::large_file) was not true, then [`crate::ZipWriter`] will
31/// raise an [`std::io::Error`] with [`std::io::ErrorKind::Other`].
32///
33/// If the zip file itself is larger than this value, then a zip64 central directory record will be
34/// written to the end of the file.
35///
36///```
37/// # fn main() -> Result<(), zip::result::ZipError> {
38/// # #[cfg(target_pointer_width = "64")]
39/// # #[cfg(all(target_endian = "little", not(miri)))] // too long to run on miri
40/// # {
41/// use std::io::{self, Cursor, Write};
42/// use std::error::Error;
43/// use zip::{ZipWriter, write::SimpleFileOptions};
44///
45/// let mut zip = ZipWriter::new(Cursor::new(Vec::new()));
46/// // Writing an extremely large file for this test is faster without compression.
47///
48/// let big_len: usize = (zip::ZIP64_BYTES_THR as usize) + 1;
49/// let big_buf = vec![0u8; big_len];
50/// {
51/// let options = SimpleFileOptions::default()
52/// .compression_method(zip::CompressionMethod::Stored);
53/// zip.start_file("zero.dat", options)?;
54/// // This is too big!
55/// let res = zip.write_all(&big_buf[..]).err().unwrap();
56/// assert_eq!(res.kind(), io::ErrorKind::Other);
57/// let description = format!("{}", &res);
58/// assert_eq!(description, "Large file option has not been set");
59/// // Attempting to write anything further to the same zip will still succeed, but the previous
60/// // failing entry has been removed.
61/// zip.start_file("one.dat", options)?;
62/// let zip = zip.finish_into_readable()?;
63/// let names: Vec<_> = zip.file_names().collect();
64/// assert_eq!(names[0].as_ref().unwrap(), "one.dat");
65/// }
66///
67/// // Create a new zip output.
68/// let mut zip = ZipWriter::new(Cursor::new(Vec::new()));
69/// // This time, create a zip64 record for the file.
70/// let options = SimpleFileOptions::default()
71/// .compression_method(zip::CompressionMethod::Stored)
72/// .large_file(true);
73/// zip.start_file("zero.dat", options)?;
74/// // This succeeds because we specified that it could be a large file.
75/// assert!(zip.write_all(&big_buf[..]).is_ok());
76/// # }
77/// # Ok(())
78/// # }
79///```
80pub const ZIP64_BYTES_THR: u64 = u32::MAX as u64;
81
82/// Same as `ZIP64_BYTES_THR` but as `u32`
83pub const ZIP64_BYTES_THR_U32: u32 = u32::MAX;
84
85/// The number of entries within a single zip necessary to allocate a zip64 central
86/// directory record.
87///
88/// If more than this number of entries is written to a [`crate::ZipWriter`], then [`crate::ZipWriter::finish()`]
89/// will write out extra zip64 data to the end of the zip file.
90pub const ZIP64_ENTRY_THR: usize = u16::MAX as usize;
91
92/// Minimal version needed
93pub const MIN_VERSION: u8 = 10;
94/// Default version needed
95pub const DEFAULT_VERSION: u8 = 45;