Writer

Struct Writer 

Source
pub struct Writer<W> { /* private fields */ }
Expand description

A 7z archive writer.

Implementations§

Source§

impl<W: Write + Seek> Writer<W>

Source

pub fn add_path( &mut self, disk_path: impl AsRef<Path>, archive_path: ArchivePath, ) -> Result<()>

Adds a file from a filesystem path.

§Arguments
  • disk_path - Path to the file on disk
  • archive_path - Path within the archive
§Errors

Returns an error if the file cannot be read or if the writer is in an invalid state.

Source

pub fn add_directory( &mut self, archive_path: ArchivePath, meta: EntryMeta, ) -> Result<()>

Adds a directory entry.

§Arguments
  • archive_path - Path within the archive
  • meta - Entry metadata
§Errors

Returns an error if the writer is in an invalid state.

Source

pub fn add_anti_item(&mut self, archive_path: ArchivePath) -> Result<()>

Adds an anti-item entry (file marked for deletion in incremental backups).

Anti-items are empty entries that indicate a file or directory should be deleted when the incremental archive is applied. This is useful for incremental backup systems.

§Arguments
  • archive_path - Path within the archive to mark for deletion
§Example
let mut writer = Writer::create_file("incremental.7z")?;
writer.add_anti_item(ArchivePath::new("deleted_file.txt")?)?;
writer.finish()?;
Source

pub fn add_anti_directory(&mut self, archive_path: ArchivePath) -> Result<()>

Adds an anti-item directory (directory marked for deletion).

§Arguments
  • archive_path - Directory path within the archive to mark for deletion
Source

pub fn add_stream( &mut self, archive_path: ArchivePath, source: &mut dyn Read, meta: EntryMeta, ) -> Result<()>

Adds data from a stream.

§Arguments
  • archive_path - Path within the archive
  • source - Reader providing the data
  • meta - Entry metadata
§Errors

Returns an error if compression fails or if the writer is in an invalid state.

Source

pub fn add_bytes( &mut self, archive_path: ArchivePath, data: &[u8], ) -> Result<()>

Adds data from a byte slice.

§Arguments
  • archive_path - Path within the archive
  • data - The data to add
§Errors

Returns an error if compression fails or if the writer is in an invalid state.

Source§

impl Writer<BufWriter<File>>

Source

pub fn create_path(path: impl AsRef<Path>) -> Result<Self>

Creates a new archive file at the given path.

§Arguments
  • path - Path to the archive file to create
§Errors

Returns an error if the file cannot be created.

Source

pub fn finish(self) -> Result<WriteResult>

Finishes writing the archive.

§Returns

A WriteResult with statistics about the written archive.

§Errors

Returns an error if header writing fails.

Source§

impl Writer<Cursor<Vec<u8>>>

Source

pub fn finish(self) -> Result<WriteResult>

Finishes writing the archive to an owned cursor.

Source§

impl Writer<Cursor<&mut Vec<u8>>>

Source

pub fn finish(self) -> Result<WriteResult>

Finishes writing the archive to a borrowed cursor.

Source§

impl Writer<MultiVolumeWriter>

Source

pub fn create_multivolume(config: VolumeConfig) -> Result<Self>

Creates a new multi-volume archive writer.

The archive will be split across multiple files when each volume reaches the configured size limit.

§Arguments
  • config - Volume configuration specifying size and base path
§Errors

Returns an error if the first volume file cannot be created.

§Example
use zesven::{Writer, VolumeConfig, ArchivePath};

let config = VolumeConfig::new("archive.7z", 50 * 1024 * 1024); // 50 MB volumes
let mut writer = Writer::create_multivolume(config)?;
writer.add_bytes(ArchivePath::new("data.bin")?, &large_data)?;
let result = writer.finish()?;
println!("Created {} volumes", result.volume_count);
Source

pub fn finish(self) -> Result<WriteResult>

Finishes writing the multi-volume archive.

This finalizes all volumes and returns a WriteResult with volume information.

§Returns

A WriteResult with statistics including volume_count and volume_sizes.

§Errors

Returns an error if header writing or volume finalization fails.

Source§

impl<W: Write + Seek> Writer<W>

Source

pub fn create(sink: W) -> Result<Self>

Creates a new archive writer.

§Arguments
  • sink - The writer to output archive data to
§Errors

Returns an error if the initial seek fails.

Source

pub fn options(self, options: WriteOptions) -> Self

Sets the write options.

Source

pub fn finish_into_inner(self) -> Result<(WriteResult, W)>

Finishes writing the archive and returns the underlying sink.

This is useful when you need access to the written data, such as when writing to a Cursor<Vec<u8>> and need to retrieve the buffer.

§Returns

A tuple of (WriteResult, W) where W is the underlying sink.

§Errors

Returns an error if header writing fails.

§Example
use zesven::write::Writer;
use std::io::Cursor;

let mut writer = Writer::create(Cursor::new(Vec::new()))?;
writer.add_bytes("test.txt".try_into()?, b"Hello")?;
let (result, cursor) = writer.finish_into_inner()?;
let archive_bytes = cursor.into_inner();

Auto Trait Implementations§

§

impl<W> Freeze for Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>
where W: Send,

§

impl<W> Sync for Writer<W>
where W: Sync,

§

impl<W> Unpin for Writer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>
where W: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.