1 2 3 4 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
// Copyright (c) 2022 Harry [Majored] [hello@majored.pw]
// MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
use crate::{file::ZipFile, string::ZipString};
/// A builder for [`ZipFile`].
pub struct ZipFileBuilder(pub(crate) ZipFile);
impl From<ZipFile> for ZipFileBuilder {
fn from(file: ZipFile) -> Self {
Self(file)
}
}
impl Default for ZipFileBuilder {
fn default() -> Self {
ZipFileBuilder(ZipFile { entries: Vec::new(), zip64: false, comment: String::new().into() })
}
}
impl ZipFileBuilder {
pub fn new() -> Self {
Self::default()
}
/// Sets the file's comment.
pub fn comment(mut self, comment: ZipString) -> Self {
self.0.comment = comment;
self
}
/// Consumes this builder and returns a final [`ZipFile`].
///
/// This is equivalent to:
/// ```
/// # use async_zip::{ZipFile, ZipFileBuilder};
/// #
/// # let builder = ZipFileBuilder::new();
/// let file: ZipFile = builder.into();
/// ```
pub fn build(self) -> ZipFile {
self.into()
}
}