ZipArchiveWriterBuilder

Struct ZipArchiveWriterBuilder 

Source
pub struct ZipArchiveWriterBuilder { /* private fields */ }
Expand description

Builds a ZipArchiveWriter.

Implementations§

Source§

impl ZipArchiveWriterBuilder

Source

pub fn new() -> Self

Creates a new ZipArchiveWriterBuilder.

Source

pub fn with_capacity(self, capacity: usize) -> Self

Sets the anticipated number of files to optimize memory allocation.

Source

pub fn with_offset(self, offset: u64) -> Self

Sets the starting offset for writing. Useful when there is prelude data prior to the zip archive.

When there is prelude data, setting the offset may not technically be required, but it is recommended. For standard zip files, many zip readers can self correct when the prelude data isn’t properly declared. However for zip64 archives, setting the correct offset is required.

§Example: Appending ZIP to existing data
use std::io::{Cursor, Write, Seek, SeekFrom};

// Create a file with some prefix data
let mut output = Cursor::new(Vec::new());
output.write_all(b"This is a custom header or prefix data\n").unwrap();
let zip_start_offset = output.position();

// Create ZIP archive starting after the prefix data
let mut archive = rawzip::ZipArchiveWriter::builder()
    .with_offset(zip_start_offset)  // Tell the archive where it starts
    .build(&mut output);

// Add files normally
let mut file = archive.new_file("data.txt").create().unwrap();
let mut writer = rawzip::ZipDataWriter::new(&mut file);
writer.write_all(b"File content").unwrap();
let (_, desc) = writer.finish().unwrap();
file.finish(desc).unwrap();
archive.finish().unwrap();

// The resulting file contains both prefix data and the ZIP archive
let final_data = output.into_inner();
assert!(final_data.starts_with(b"This is a custom header"));
Source

pub fn build<W>(&self, writer: W) -> ZipArchiveWriter<W>

Builds a ZipArchiveWriter that writes to writer.

Trait Implementations§

Source§

impl Debug for ZipArchiveWriterBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ZipArchiveWriterBuilder

Source§

fn default() -> ZipArchiveWriterBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.