ArchiveWriter

Struct ArchiveWriter 

Source
pub struct ArchiveWriter<W: AsyncWrite + AsyncSeek + Unpin> { /* private fields */ }
Available on crate feature compress only.
Expand description

Writes a 7z archive file.

Implementations§

Source§

impl ArchiveWriter<Cursor<Vec<u8>>>

Source

pub async fn create_in_memory() -> Result<Self, Error>

Available on non-WebAssembly only.

创建一个基于内存缓冲的 7z 写入器。

返回使用 Vec<u8> 作为底层存储的 ArchiveWriter,适合测试或无需落盘的场景。

Source§

impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>

Source

pub async fn new(writer: W) -> Result<Self, Error>

Prepares writer to write a 7z archive to.

Source

pub fn auto_finish(self) -> AutoFinisher<Self>

Returns a wrapper around self that will finish the stream on drop.

Source

pub fn set_content_methods( &mut self, content_methods: Vec<EncoderConfiguration>, ) -> &mut Self

Sets the default compression methods to use for entry data. Default is LZMA2.

Source

pub fn set_encrypt_header(&mut self, enabled: bool)

Whether to enable the encryption of the -header. Default is true.

Source

pub async fn push_archive_entry<R: AsyncRead + Unpin>( &mut self, entry: ArchiveEntry, reader: Option<R>, ) -> Result<&ArchiveEntry, Error>

Non-solid compression - Adds an archive entry with data from reader.

§Example
use std::io::Cursor;
use std::path::Path;
use async_sevenz::*;
#[tokio::main]
async fn main() {
    let mut sz = ArchiveWriter::create_in_memory().await.expect("create writer ok");
    let src = Path::new("path/to/source.txt");
    let name = "source.txt".to_string();
    let entry = sz
        .push_archive_entry(
            ArchiveEntry::from_path(&src, name).await,
            Some(futures_lite::io::Cursor::new(&b"example"[..])),
        )
        .await
        .expect("ok");
    let compressed_size = entry.compressed_size;
    let _cursor = sz.finish().await.expect("done");
}
Source

pub async fn push_archive_entries<R: AsyncRead + Unpin>( &mut self, entries: Vec<ArchiveEntry>, reader: Vec<SourceReader<R>>, ) -> Result<&mut Self, Error>

Solid compression - packs entries into one pack.

§Panics
  • If entries’s length not equals to reader.reader_len()
Source

pub async fn finish(self) -> Result<W>

Finishes the compression.

Source§

impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>

Source

pub async fn push_source_path<Fut>( &mut self, path: impl AsRef<Path>, filter: impl FnMut(&Path) -> Fut, ) -> Result<(), Error>
where Fut: Future<Output = bool>,

Available on non-WebAssembly only.

Adds a source path to the compression builder with a filter function using solid compression.

The filter function allows selective inclusion of files based on their paths. Files are compressed using solid compression for better compression ratios.

§Arguments
  • path - Path to add to the compression
  • filter - Function that returns true for paths that should be included
Source

pub async fn push_source_path_non_solid<Fut>( &mut self, path: impl AsRef<Path>, filter: impl FnMut(&Path) -> Fut, ) -> Result<(), Error>
where Fut: Future<Output = bool>,

Available on non-WebAssembly only.

Adds a source path to the compression builder with a filter function using non-solid compression.

Non-solid compression allows individual file extraction without decompressing the entire archive, but typically results in larger archive sizes compared to solid compression.

§Arguments
  • path - Path to add to the compression
  • filter - Function that returns true for paths that should be included

Trait Implementations§

Source§

impl<W: AsyncWrite + AsyncSeek + Unpin> AutoFinish for ArchiveWriter<W>

Source§

fn finish_ignore_error(self)

Finish writing the stream without error handling.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<W> Unpin for ArchiveWriter<W>

§

impl<W> UnwindSafe for ArchiveWriter<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> 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.