| 1 | // Copyright (c) 2022 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | use craterust-analyzer cargo async_zip 0.0.18 crate/::entryrust-analyzer cargo async_zip 0.0.18 entry/::ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#; |
| 5 | use craterust-analyzer cargo async_zip 0.0.18 crate/::specrust-analyzer cargo async_zip 0.0.18 spec/::{attributerust-analyzer cargo async_zip 0.0.18 spec/attribute/::AttributeCompatibilityrust-analyzer cargo async_zip 0.0.18 spec/attribute/AttributeCompatibility#, headerrust-analyzer cargo async_zip 0.0.18 spec/header/::ExtraFieldrust-analyzer cargo async_zip 0.0.18 spec/header/ExtraField#, Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#}; |
| 6 | use craterust-analyzer cargo async_zip 0.0.18 crate/::{daterust-analyzer cargo async_zip 0.0.18 date/::ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#, stringrust-analyzer cargo async_zip 0.0.18 string/::ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#}; |
| 7 | |
| 8 | /// A builder for [`ZipEntry`]. |
| 9 | pub struct ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#(pub(craterust-analyzer cargo async_zip 0.0.18 crate/) ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#); |
| 10 | |
| 11 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#> for ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder# { |
| 12 | fn fromrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder][`From<ZipEntry>`]from().(entry: ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder][`From<ZipEntry>`] { |
| 13 | Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder][`From<ZipEntry>`](entry) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder# { |
| 18 | /// Constructs a new builder which defines the raw underlying data of a ZIP entry. |
| 19 | /// |
| 20 | /// A filename and compression method are needed to construct the builder as minimal parameters. |
| 21 | pub fn newrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]new().(filename: ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#, compression: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 22 | Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder](ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#::newrust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]new().(filename, compression)) |
| 23 | } |
| 24 | |
| 25 | /// Sets the entry's filename. |
| 26 | pub fn filenamerust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]filename().(mut self, filename: ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 27 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..filenamerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#filename. = filename; |
| 28 | self |
| 29 | } |
| 30 | |
| 31 | /// Sets the entry's compression method. |
| 32 | pub fn compressionrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]compression().(mut self, compression: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 33 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..compressionrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#compression. = compression; |
| 34 | self |
| 35 | } |
| 36 | |
| 37 | // Sets the entry's CRC32 checksum. |
| 38 | pub fn crc32rust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]crc32().<N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u32>>(mut self, crc: N) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 39 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..crc32rust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#crc32. = crc.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 40 | self |
| 41 | } |
| 42 | |
| 43 | // Sets the entry's compressed size. |
| 44 | pub fn compressed_sizerust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]compressed_size().<N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u64>>(mut self, size: N) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 45 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..compressed_sizerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#compressed_size. = size.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 46 | self |
| 47 | } |
| 48 | |
| 49 | // Sets the entry's uncompressed size. |
| 50 | pub fn uncompressed_sizerust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]uncompressed_size().<N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u64>>(mut self, size: N) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 51 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..uncompressed_sizerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#uncompressed_size. = size.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 52 | self |
| 53 | } |
| 54 | |
| 55 | /// Set the deflate compression option. |
| 56 | /// |
| 57 | /// If the compression type isn't deflate, this option has no effect. |
| 58 | #[cfg(any(feature = "deflate", feature = "bzip2", feature = "zstd", feature = "lzma", feature = "xz"))] |
| 59 | pub fn deflate_optionrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]deflate_option().(mut self, option: craterust-analyzer cargo async_zip 0.0.18 crate/::DeflateOptionrust-analyzer cargo async_zip 0.0.18 spec/compression/DeflateOption#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 60 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..compression_levelrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#compression_level. = option.into_levelrust-analyzer cargo async_zip 0.0.18 spec/compression/impl#[DeflateOption]into_level().(); |
| 61 | self |
| 62 | } |
| 63 | |
| 64 | /// Sets the entry's attribute host compatibility. |
| 65 | pub fn attribute_compatibilityrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]attribute_compatibility().(mut self, compatibility: AttributeCompatibilityrust-analyzer cargo async_zip 0.0.18 spec/attribute/AttributeCompatibility#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 66 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..attribute_compatibilityrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#attribute_compatibility. = compatibility; |
| 67 | self |
| 68 | } |
| 69 | |
| 70 | /// Sets the entry's last modification date. |
| 71 | pub fn last_modification_daterust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]last_modification_date().(mut self, date: ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 72 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..last_modification_daterust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#last_modification_date. = date; |
| 73 | self |
| 74 | } |
| 75 | |
| 76 | /// Sets the entry's internal file attribute. |
| 77 | pub fn internal_file_attributerust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]internal_file_attribute().(mut self, attribute: u16) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 78 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..internal_file_attributerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#internal_file_attribute. = attribute; |
| 79 | self |
| 80 | } |
| 81 | |
| 82 | /// Sets the entry's external file attribute. |
| 83 | pub fn external_file_attributerust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]external_file_attribute().(mut self, attribute: u32) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 84 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..external_file_attributerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#external_file_attribute. = attribute; |
| 85 | self |
| 86 | } |
| 87 | |
| 88 | /// Sets the entry's extra field data. |
| 89 | pub fn extra_fieldsrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]extra_fields().(mut self, field: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ExtraFieldrust-analyzer cargo async_zip 0.0.18 spec/header/ExtraField#>) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 90 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..extra_fieldsrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#extra_fields. = field; |
| 91 | self |
| 92 | } |
| 93 | |
| 94 | /// Sets the entry's file comment. |
| 95 | pub fn commentrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]comment().(mut self, comment: ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 96 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..commentrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#comment. = comment; |
| 97 | self |
| 98 | } |
| 99 | |
| 100 | /// Sets the entry's Unix permissions mode. |
| 101 | /// |
| 102 | /// If the attribute host compatibility isn't set to Unix, this will have no effect. |
| 103 | pub fn unix_permissionsrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]unix_permissions().(mut self, mode: u16) -> Selfrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder] { |
| 104 | if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..attribute_compatibilityrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#attribute_compatibility., AttributeCompatibilityrust-analyzer cargo async_zip 0.0.18 spec/attribute/AttributeCompatibility#::Unixrust-analyzer cargo async_zip 0.0.18 spec/attribute/AttributeCompatibility#Unix#) { |
| 105 | self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..external_file_attributerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#external_file_attribute. = (self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0..external_file_attributerust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#external_file_attribute. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0xFFFF) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(mode as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().16; |
| 106 | } |
| 107 | self |
| 108 | } |
| 109 | |
| 110 | /// Returns a reference to the currently built entry. |
| 111 | pub fn currentrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]current().(&self) -> &ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry# { |
| 112 | &self.0rust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#0. |
| 113 | } |
| 114 | |
| 115 | /// Consumes this builder and returns a final [`ZipEntry`]. |
| 116 | /// |
| 117 | /// This is equivalent to: |
| 118 | /// ``` |
| 119 | /// # use async_zip::{ZipEntry, ZipEntryBuilder, Compression}; |
| 120 | /// # |
| 121 | /// # let builder = ZipEntryBuilder::new(String::from("foo.bar").into(), Compression::Stored); |
| 122 | /// let entry: ZipEntry = builder.into(); |
| 123 | /// ``` |
| 124 | pub fn buildrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]build().(self) -> ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry# { |
| 125 | self.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 126 | } |
| 127 | } |