Skip to content
Merged
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
15 changes: 10 additions & 5 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ impl CompressionMethod {
pub const AES: Self = CompressionMethod::Aes;
#[cfg(not(feature = "aes-crypto"))]
pub const AES: Self = CompressionMethod::Unsupported(99);

#[cfg(feature = "_deflate-any")]
pub const DEFAULT: Self = CompressionMethod::Deflated;

#[cfg(all(not(feature = "_deflate-any"), feature = "bzip2"))]
pub const DEFAULT: Self = CompressionMethod::Bzip2;

#[cfg(all(not(feature = "_deflate-any"), not(feature = "bzip2")))]
pub const DEFAULT: Self = CompressionMethod::Stored;
}
impl CompressionMethod {
pub(crate) const fn parse_from_u16(val: u16) -> Self {
Expand Down Expand Up @@ -228,11 +237,7 @@ impl CompressionMethod {

impl Default for CompressionMethod {
fn default() -> Self {
#[cfg(feature = "_deflate-any")]
return CompressionMethod::Deflated;

#[cfg(not(feature = "_deflate-any"))]
return CompressionMethod::Stored;
Self::DEFAULT
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ impl PartialOrd for DateTime {
}

impl DateTime {
/// Constructs a default datetime of 1980-01-01 00:00:00.
pub const DEFAULT: Self = DateTime {
datepart: 0b0000000000100001,
timepart: 0,
};

/// Returns the current time if possible, otherwise the default of 1980-01-01.
#[cfg(feature = "time")]
pub fn default_for_write() -> Self {
Expand Down Expand Up @@ -256,10 +262,7 @@ impl From<DateTime> for (u16, u16) {
impl Default for DateTime {
/// Constructs an 'default' datetime of 1980-01-01 00:00:00
fn default() -> DateTime {
DateTime {
datepart: 0b0000000000100001,
timepart: 0,
}
DateTime::DEFAULT
}
}

Expand Down
29 changes: 25 additions & 4 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,9 @@ impl<T: FileOptionExtension> FileOptions<'_, T> {

/// Set the compression method for the new file
///
/// The default is `CompressionMethod::Deflated` if it is enabled. If not,
/// `CompressionMethod::Bzip2` is the default if it is enabled. If neither `bzip2` nor `deflate`
/// is enabled, `CompressionMethod::Zlib` is the default. If all else fails,
/// `CompressionMethod::Stored` becomes the default and files are written uncompressed.
/// The default is [`CompressionMethod::Deflated`] if it is enabled. If not,
/// [`CompressionMethod::Bzip2`] is the default if it is enabled. If neither `bzip2` nor `deflate`
/// is enabled, [`CompressionMethod::Stored`] becomes the default and files are written uncompressed.
#[must_use]
pub const fn compression_method(mut self, method: CompressionMethod) -> Self {
self.compression_method = method;
Expand Down Expand Up @@ -559,6 +558,28 @@ impl FileOptions<'_, ExtendedFileOptions> {
self
}
}
impl FileOptions<'static, ()> {
/// Constructs a const FileOptions object.
///
/// Note: This value is different than the return value of [`FileOptions::default()`]:
///
/// - The `last_modified_time` is [`DateTime::DEFAULT`]. This corresponds to 1980-01-01 00:00:00
pub const DEFAULT: Self = Self {
compression_method: CompressionMethod::DEFAULT,
compression_level: None,
last_modified_time: DateTime::DEFAULT,
large_file: false,
permissions: None,
encrypt_with: None,
extended_options: (),
alignment: 1,
#[cfg(feature = "deflate-zopfli")]
zopfli_buffer_size: Some(1 << 15),
#[cfg(feature = "aes-crypto")]
aes_mode: None,
};
}

impl<T: FileOptionExtension> Default for FileOptions<'_, T> {
/// Construct a new FileOptions object
fn default() -> Self {
Expand Down
Loading