Struct FileOptions

#[non_exhaustive]
pub struct FileOptions<'k, T: FileOptionExtension> { /* private fields */ }

Metadata for a file to be written

Implementations

impl FileOptions<'_, ExtendedFileOptions>

fn with_file_comment<S: Into<Box<str>>>(self, comment: S) -> Self

Set the file comment.

fn add_extra_data<D: AsRef<[u8]>>(&mut self, header_id: u16, data: D, central_only: bool) -> ZipResult<()>

Adds an extra data field.

fn clear_extra_data(self) -> Self

Removes the extra data fields.

impl FileOptions<'static, ()>

const DEFAULT: Self = _;

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

impl<'k> FileOptions<'k, ()>

fn into_full_options(self) -> FullFileOptions<'k>

Convert to FullFileOptions.

impl<T: FileOptionExtension> FileOptions<'_, T>

const fn has_encryption(&self) -> bool

Indicates whether this file will be encrypted (whether with AES or ZipCrypto).

const fn compression_method(self, method: CompressionMethod) -> Self

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::Stored becomes the default and files are written uncompressed.

const fn system(self, system: System) -> Self

Set the system field for the new file

If not set, the zip crate will use the current system

const fn compression_level(self, level: Option<i64>) -> Self

Set the compression level for the new file

None value specifies default compression level.

Range of values depends on compression method:

  • Deflated: 10 - 264 for Zopfli, 0 - 9 for other encoders. Default is 24 if Zopfli is the only encoder, or 6 otherwise.
  • Bzip2: 0 - 9. Default is 6
  • Zstd: -7 - 22, with zero being mapped to default level. Default is 3
  • others: only None is allowed
const fn last_modified_time(self, mod_time: DateTime) -> Self

Set the last modified time

The default is the current timestamp if the 'time' feature is enabled, and 1980-01-01 otherwise

const fn unix_permissions(self, mode: u32) -> Self

Set the permissions for the new file.

The format is represented with unix-style permissions. The default is 0o644, which represents rw-r--r-- for files, and 0o755, which represents rwxr-xr-x for directories.

This method only preserves the file permissions bits (via a & 0o777) and discards higher file mode bits. So it cannot be used to denote an entry as a directory, symlink, or other special file type.

const fn large_file(self, large: bool) -> Self

Set whether the new file's compressed and uncompressed size is less than 4 GiB.

If set to false and the file exceeds the limit, an I/O error is thrown and the file is aborted. If set to true, readers will require ZIP64 support and if the file does not exceed the limit, 20 B are wasted. The default is false.

fn with_aes_encryption_and_salt(self, password: &[u8], salt: AesSalt) -> FileOptions<'_, T>

Set the AES encryption parameters. The salt must be at least 8 bytes long for AES-128, and at least 16 bytes long for AES-256. This method is not recommended, since having a fixed salt is not secure. Consider using with_aes_encryption instead, which uses a random salt and is more secure.

fn with_aes_encryption(self, mode: AesMode, password: &str) -> FileOptions<'_, T>

Set the AES encryption parameters.

fn with_aes_encryption_bytes(self, mode: AesMode, password: &[u8]) -> FileOptions<'_, T>

Set the AES encryption parameters.

const fn with_zopfli_buffer(self, size: Option<usize>) -> Self

Sets the size of the buffer used to hold the next block that Zopfli will compress. The larger the buffer, the more effective the compression, but the more memory is required. A value of None indicates no buffer, which is recommended only when all non-empty writes are larger than about 32 KiB.

const fn get_compression_level(&self) -> Option<i64>

Returns the compression level currently set.

const fn with_alignment(self, alignment: u16) -> Self

Sets the alignment to the given number of bytes.

Trait Implementations

impl<'k, T: Clone + FileOptionExtension> Clone for FileOptions<'k, T>

fn clone(&self) -> FileOptions<'k, T>

impl<'k, T: Copy + FileOptionExtension> Copy for FileOptions<'k, T>

impl<'k, T: Debug + FileOptionExtension> Debug for FileOptions<'k, T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<'k, T: Eq + FileOptionExtension> Eq for FileOptions<'k, T>

impl<'k, T: PartialEq + FileOptionExtension> PartialEq for FileOptions<'k, T>

fn eq(&self, other: &FileOptions<'k, T>) -> bool

impl<'k, T: PartialEq + FileOptionExtension> StructuralPartialEq for FileOptions<'k, T>

impl<T: FileOptionExtension> Default for FileOptions<'_, T>

fn default() -> Self

Construct a new FileOptions object

impl<T: FileOptionExtension> FileOptionsExt for FileOptions<'_, T>

fn with_deprecated_encryption(self, password: &[u8]) -> ZipResult<FileOptions<'static, T>>

Auto Trait Implementations

impl<'k, T> Freeze for FileOptions<'k, T> where T: Freeze,

impl<'k, T> RefUnwindSafe for FileOptions<'k, T> where T: RefUnwindSafe,

impl<'k, T> Send for FileOptions<'k, T> where T: Send,

impl<'k, T> Sync for FileOptions<'k, T> where T: Sync,

impl<'k, T> Unpin for FileOptions<'k, T> where T: Unpin,

impl<'k, T> UnsafeUnpin for FileOptions<'k, T> where T: UnsafeUnpin,

impl<'k, T> UnwindSafe for FileOptions<'k, T> where T: UnwindSafe,

Blanket Implementations

impl<Q, K> Equivalent<K> for FileOptions<'k, T> where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<Q, K> Equivalent<K> for FileOptions<'k, T> where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<T> Any for FileOptions<'k, T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for FileOptions<'k, T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for FileOptions<'k, T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for FileOptions<'k, T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for FileOptions<'k, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for FileOptions<'k, T>

type Output = T;

impl<T> ToOwned for FileOptions<'k, T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for FileOptions<'k, T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for FileOptions<'k, T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for FileOptions<'k, T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>