Struct GzBuilder

struct GzBuilder { ... }

A builder structure to create a new gzip Encoder.

This structure controls header configuration options such as the filename.

Examples

use std::io::prelude::*;
# use std::io;
use std::fs::File;
use flate2::GzBuilder;
use flate2::Compression;

// GzBuilder opens a file and writes a sample string using GzBuilder pattern

# fn sample_builder() -> Result<(), io::Error> {
let f = File::create("examples/hello_world.gz")?;
let mut gz = GzBuilder::new()
                .filename("hello_world.txt")
                .comment("test file, please delete")
                .write(f, Compression::default());
gz.write_all(b"hello world")?;
gz.finish()?;
# Ok(())
# }

Implementations

impl GzBuilder

fn new() -> GzBuilder

Create a new blank builder with no header by default.

fn mtime(self: Self, mtime: u32) -> GzBuilder

Configure the mtime field in the gzip header.

fn operating_system(self: Self, os: u8) -> GzBuilder

Configure the operating_system field in the gzip header.

fn extra<T: Into<Vec<u8>>>(self: Self, extra: T) -> GzBuilder

Configure the extra field in the gzip header.

fn filename<T: Into<Vec<u8>>>(self: Self, filename: T) -> GzBuilder

Configure the filename field in the gzip header.

Panics

Panics if the filename slice contains a zero.

fn comment<T: Into<Vec<u8>>>(self: Self, comment: T) -> GzBuilder

Configure the comment field in the gzip header.

Panics

Panics if the comment slice contains a zero.

fn write<W: Write>(self: Self, w: W, lvl: Compression) -> GzEncoder<W>

Consume this builder, creating a writer encoder in the process.

The data written to the returned encoder will be compressed and then written out to the supplied parameter w.

fn read<R: Read>(self: Self, r: R, lvl: Compression) -> GzEncoder<R>

Consume this builder, creating a reader encoder in the process.

Data read from the returned encoder will be the compressed version of the data read from the given reader.

fn buf_read<R>(self: Self, r: R, lvl: Compression) -> GzEncoder<R>
where
    R: BufRead

Consume this builder, creating a reader encoder in the process.

Data read from the returned encoder will be the compressed version of the data read from the given reader.

impl Debug for GzBuilder

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Default for GzBuilder

fn default() -> GzBuilder

impl Freeze for GzBuilder

impl RefUnwindSafe for GzBuilder

impl Send for GzBuilder

impl Sync for GzBuilder

impl Unpin for GzBuilder

impl UnsafeUnpin for GzBuilder

impl UnwindSafe for GzBuilder

impl<T> Any for GzBuilder

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for GzBuilder

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for GzBuilder

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for GzBuilder

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for GzBuilder

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for GzBuilder

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for GzBuilder

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>