pub struct ArchiveWriter<W: AsyncWrite + AsyncSeek + Unpin> { /* private fields */ }compress only.Expand description
Writes a 7z archive file.
Implementations§
Source§impl ArchiveWriter<Cursor<Vec<u8>>>
impl ArchiveWriter<Cursor<Vec<u8>>>
Sourcepub async fn create_in_memory() -> Result<Self, Error>
Available on non-WebAssembly only.
pub async fn create_in_memory() -> Result<Self, Error>
创建一个基于内存缓冲的 7z 写入器。
返回使用 Vec<u8> 作为底层存储的 ArchiveWriter,适合测试或无需落盘的场景。
Source§impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>
impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>
Sourcepub fn auto_finish(self) -> AutoFinisher<Self>
pub fn auto_finish(self) -> AutoFinisher<Self>
Returns a wrapper around self that will finish the stream on drop.
Sourcepub fn set_content_methods(
&mut self,
content_methods: Vec<EncoderConfiguration>,
) -> &mut Self
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.
Sourcepub fn set_encrypt_header(&mut self, enabled: bool)
pub fn set_encrypt_header(&mut self, enabled: bool)
Whether to enable the encryption of the -header. Default is true.
Sourcepub async fn push_archive_entry<R: AsyncRead + Unpin>(
&mut self,
entry: ArchiveEntry,
reader: Option<R>,
) -> Result<&ArchiveEntry, Error>
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");
}Sourcepub async fn push_archive_entries<R: AsyncRead + Unpin>(
&mut self,
entries: Vec<ArchiveEntry>,
reader: Vec<SourceReader<R>>,
) -> Result<&mut Self, Error>
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 toreader.reader_len()
Source§impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>
impl<W: AsyncWrite + AsyncSeek + Unpin> ArchiveWriter<W>
Sourcepub async fn push_source_path<Fut>(
&mut self,
path: impl AsRef<Path>,
filter: impl FnMut(&Path) -> Fut,
) -> Result<(), Error>
Available on non-WebAssembly only.
pub async fn push_source_path<Fut>( &mut self, path: impl AsRef<Path>, filter: impl FnMut(&Path) -> Fut, ) -> Result<(), Error>
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 compressionfilter- Function that returnstruefor paths that should be included
Sourcepub async fn push_source_path_non_solid<Fut>(
&mut self,
path: impl AsRef<Path>,
filter: impl FnMut(&Path) -> Fut,
) -> Result<(), Error>
Available on non-WebAssembly only.
pub async fn push_source_path_non_solid<Fut>( &mut self, path: impl AsRef<Path>, filter: impl FnMut(&Path) -> Fut, ) -> Result<(), Error>
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 compressionfilter- Function that returnstruefor paths that should be included