pub struct TgzWriter<W: Write> { /* private fields */ }Expand description
Compressor for producing .tar.gz files with embedded chapter information.
Most of the API surface area is in the tar crate.
§Example
This example creates a tgz with several large files containing random data, each in its own chapter.
use chapter_tgz::{Compression, TgzWriter};
use rand::RngReader;
use rand::rngs::SmallRng;
use std::fs;
use std::io::{self, Read as _};
fn main() -> io::Result<()> {
let mut tgz = TgzWriter::new(Vec::new(), Compression::fast());
let mut rng: SmallRng = rand::make_rng();
for i in 0..20 {
let mut chapter = tgz.create_chapter();
let mut header = tar::Header::new_gnu();
header.set_size(100_000_000);
let path = format!("random/{i}");
let data = RngReader(&mut rng).take(100_000_000);
chapter.append_data(&mut header, path, data)?;
}
let compressed = tgz.into_inner()?;
fs::write("example.tar.gz", compressed)?;
Ok(())
}Implementations§
Source§impl<W> TgzWriter<W>where
W: Write,
impl<W> TgzWriter<W>where
W: Write,
pub fn new(out: W, level: Compression) -> Self
Sourcepub fn create_chapter(&mut self) -> Builder<ChapterWriter<'_, W>>
pub fn create_chapter(&mut self) -> Builder<ChapterWriter<'_, W>>
Begin writing the next chapters.
A chapter may contain zero or more tar entries.
The total number of chapters is limited to u32::MAX.
§Panics
Panics if 4,294,967,295 previous chapters have already been created in this tgz.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Flush the last chapter information to the underlying writer.
This is done automatically by Drop, but calling it explicitly allows
any error to be handled. Drop would ignore the error.
§Panics
Panics if finish has already been called on this tgz.
Sourcepub fn into_inner(self) -> Result<W>
pub fn into_inner(self) -> Result<W>
Flush the last chapter information to the underlying writer and return the writer object.
It is not necessary to call finish before into_inner.