Skip to main content

TgzWriter

Struct TgzWriter 

Source
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,

Source

pub fn new(out: W, level: Compression) -> Self

Source

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.

Source

pub fn chapters(&self) -> u32

Number of chapters created so far.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<W> Drop for TgzWriter<W>
where W: Write,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnsafeUnpin for TgzWriter<W>
where W: UnsafeUnpin,

§

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